1 Object-Oriented Design Now we can extend our discussion of the design of classes and objects Chapter 6 focuses on: software development activities determining.

Slides:



Advertisements
Similar presentations
CSCI 1100/1202 April 3, Testing A program should be executed multiple times with various input in an attempt to find errors Debugging is the process.
Advertisements

Problem Solving #1 ICS Outline Review of Key Topics Review of Key Topics Example Program Example Program –Problem 7.1 Problem Solving Tips Problem.
Object Oriented Design and UML
Chapter 6 Object-Oriented Design. 6-2 Program Development The creation of software involves four basic activities:  establishing the requirements  creating.
Chapter 6 Object-Oriented Design. © 2004 Pearson Addison-Wesley. All rights reserved6-2 Object-Oriented Design Now we can extend our discussion of the.
ECE122 L16: Class Relationships April 3, 2007 ECE 122 Engineering Problem Solving with Java Lecture 16 Class Relationships.
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
Classes, Encapsulation, Methods and Constructors
Aalborg Media Lab 28-Jun-15 Software Design Lecture 7 “Object Oriented Design”
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
ECE122 L17: Method Development and Testing April 5, 2007 ECE 122 Engineering Problem Solving with Java Lecture 17 Method Development and Testing.
INF 523Q Chapter 5: Enhancing Classes. 2 b We can now explore various aspects of classes and objects in more detail b Chapter 5 focuses on: object references.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
1 Object Oriented Design and UML Software Development Activities Object Oriented Design Unified Modeling Language (UML) Reading for this Lecture: L&L 6.1.
Object Oriented Design and UML
Writing Classes (Chapter 4)
The this Reference The this reference, used inside a method, refers to the object through which the method is being executed Suppose the this reference.
CSE 1301 Lecture 11 Object Oriented Programming Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Chapter 6 Object-Oriented Design. © 2004 Pearson Addison-Wesley. All rights reserved6-2 Object-Oriented Design Now we can extend our discussion of the.
© 2004 Pearson Addison-Wesley. All rights reserved November 9, 2007 Method Design & Method Overloading ComS 207: Programming I (in Java) Iowa State University,
6-1 Object-Oriented Design Today we focuses on: –the this reference (Chapter 7) –the static modifier (Chapter 7) –method overloading (Chapter 7)
CSE 1302 Lecture 7 Object Oriented Programming Review Richard Gesick.
Chapter 6 Object-Oriented Design Part 1. © 2004 Pearson Addison-Wesley. All rights reserved2/42 Object-Oriented Design Now we can extend our discussion.
1 Object Oriented Design and UML Class Relationships –Dependency –Aggregation –Inheritance Reading for this Lecture: L&L 6.4 – 6.5.
© 2004 Pearson Addison-Wesley. All rights reserved November 7, 2007 Interfaces ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Chapter 6 Object-Oriented Design Part 3. © 2004 Pearson Addison-Wesley. All rights reserved6-2 Outline Enumerated Types Revisited Method Design Testing.
6. Object-Oriented Design Based on Java Software Development, 5 th Ed. By Lewis &Loftus.
6. Object-Oriented Design Based on Java Software Development, 5 th Ed. By Lewis &Loftus.
Programming in Java (COP 2250) Lecture 14 & 15 Chengyong Yang Fall, 2005.
1 Object Oriented Design and UML Class Relationships –Dependency –Aggregation –Interfaces –Inheritance Interfaces Reading for this Lecture: L&L 6.4 – 6.5.
Chapter 6 Object-Oriented Design. © 2004 Pearson Addison-Wesley. All rights reserved6-2 Object-Oriented Design Now we can extend our discussion of the.
Static class members.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
Designing Classes CS239 – Jan 26, Key points from yesterday’s lab  Enumerated types are abstract data types that define a set of values.  They.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
Chapter 6 Object-Oriented Design Part 2. © 2004 Pearson Addison-Wesley. All rights reserved2/20 The this Reference The this reference allows an object.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
Lecture 4 b Writing Classes b class declarations b method declarations b constructors b instance variables b encapsulation b method overloading b program.
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
1 Object-Oriented Design Now we can extend our discussion of the design of classes and objects Chapter 6 focuses on: software development activities determining.
1 b Boolean expressions b truth tables b conditional operator b switch statement b repetition statements: whilewhile do/whiledo/while forfor Lecture 3.
Chapter 8 Inheritance 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights reserved.
© 2004 Pearson Addison-Wesley. All rights reserved October 31, 2007 Static Class Members ComS 207: Programming I (in Java) Iowa State University, FALL.
© 2004 Pearson Addison-Wesley. All rights reserved November 12, 2007 Inheritance ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Outline Software Development Activities Identifying Classes and Objects Static Variables and Methods Class Relationships Interfaces Enumerated Types Revisited.
Testing JUnit Testing. Testing Testing can mean many different things It certainly includes running a completed program with various inputs It also includes.
1 Chapter 4: Writing Classes  Chapter 4 focuses on: class definitions encapsulation and Java modifiers method declaration, invocation, and parameter passing.
© 2004 Pearson Addison-Wesley. All rights reserved April 5, 2006 Method Design & Method Overloading ComS 207: Programming I (in Java) Iowa State University,
Object-Oriented Design Chapter 7 1. Objectives You will be able to Use the this reference in a Java program. Use the static modifier for member variables.
© 2004 Pearson Addison-Wesley. All rights reserved November 2, 2007 Class Relationships ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
University of Turkish Aeronautical Association Computer Engineering Department CENG 112 COMPUTER PROGRAMMING 2 Tansel Dökeroglu, Ph.D.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes : Review Java Software Solutions Foundations of Program Design Seventh Edition John.
Chapter 7 Object-Oriented Design
Interfaces November 6, 2006 ComS 207: Programming I (in Java)
Chapter 4: Writing Classes
Inheritance November 10, 2006 ComS 207: Programming I (in Java)
Passing Objects to Methods
More Object Oriented Programming
Object Oriented Programming
Inheritance April 7, 2006 ComS 207: Programming I (in Java)
Chapter 4: Writing classes
Chapter 3: Program Statements
The this Reference The this reference allows an object to refer to itself That is, the this reference, used inside a method, refers to the object through.
Static Class Members March 29, 2006 ComS 207: Programming I (in Java)
Java Classes Aliases & Null & This
Object Oriented Programming Review
Outline Software Development Activities
Object-Oriented Design Part 2
Presentation transcript:

1 Object-Oriented Design Now we can extend our discussion of the design of classes and objects Chapter 6 focuses on: software development activities determining the classes and objects that are needed for a program the relationships that can exist among classes writing interfaces the design of enumerated type classes method design and method overloading GUI design and layout managers

2 Outline Software Development Activities Identifying Classes and Objects Class Relationships Interfaces Enumerated Types Revisited Method Design Testing GUI Design and Layout

3 Program Development The creation of software involves four basic activities: establishing the requirements creating a design implementing the code testing the implementation These activities are not strictly linear – they overlap and interact

4 Requirements Software requirements specify the tasks that a program must accomplish what to do, not how to do it Often an initial set of requirements is provided, but they should be critiqued and expanded It is difficult to establish detailed, unambiguous, and complete requirements Careful attention to the requirements can save significant time and expense in the overall project

5 Design A software design specifies how a program will accomplish its requirements That is, a software design determines: how the solution can be broken down into manageable pieces what each piece will do An object-oriented design determines which classes and objects are needed, and specifies how they will interact Low level design details include how individual methods will accomplish their tasks

6 Implementation Implementation is the process of translating a design into source code Novice programmers often think that writing code is the heart of software development, but actually it should be the least creative step Almost all important decisions are made during requirements and design stages Implementation should focus on coding details, including style guidelines and documentation

7 Testing Testing attempts to ensure that the program will solve the intended problem under all the constraints specified in the requirements A program should be thoroughly tested with the goal of finding errors Debugging is the process of determining the cause of a problem and fixing it We revisit the details of the testing process later in this chapter

8 Outline Software Development Activities Identifying Classes and Objects Class Relationships Interfaces Enumerated Types Revisited Method Design Testing GUI Design and Layout

9 Identifying Classes and Objects The core activity of object-oriented design is determining the classes and objects that will make up the solution The classes may be part of a class library, reused from a previous project, or newly written One way to identify potential classes is to identify the objects discussed in the requirements Objects are generally nouns, and the services that an object provides are generally verbs

10 Identifying Classes and Objects A partial requirements document: The user must be allowed to specify each product by its primary characteristics, including its name and product number. If the bar code does not match the product, then an error should be generated to the message window and entered into the error log. The summary report of all transactions must be structured as specified in section 7.A. Of course, not all nouns will correspond to a class or object in the final solution

11 Identifying Classes and Objects Remember that a class represents a group (classification) of objects with the same behaviors Generally, classes that represent objects should be given names that are singular nouns Examples: Coin, Student, Message A class represents the concept of one such object We are free to instantiate as many of each object as needed

12 Identifying Classes and Objects We want to define classes with the proper amount of detail For example, it may be unnecessary to create separate classes for each type of appliance in a house It may be sufficient to define a more general Appliance class with appropriate instance data It all depends on the details of the problem being solved

13 Identifying Classes and Objects Part of identifying the classes we need is the process of assigning responsibilities to each class Every activity that a program must accomplish must be represented by one or more methods in one or more classes We generally use verbs for the names of methods In early stages it is not necessary to determine every method of every class – begin with primary responsibilities and evolve the design

14 Outline Software Development Activities Identifying Classes and Objects Class Relationships Interfaces Enumerated Types Revisited Method Design Testing GUI Design and Layout

15 Aggregation An aggregate is an object that is made up of other objects Therefore aggregation is a has-a relationship A car has a chassis In software, an aggregate object contains references to other objects as instance data The aggregate object is defined in part by the objects that make it up This is a special kind of dependency – the aggregate usually relies on the objects that compose it

16 Aggregation In the following example, a Student object is composed, in part, of Address objects A student has an address (in fact each student has two addresses) See StudentBody.java (page 304)StudentBody.java See Student.java (page 306)Student.java See Address.java (page 307)Address.java An aggregation association is shown in a UML class diagram using an open diamond at the aggregate end

17 Aggregation in UML StudentBody + main (args : String[]) : void + toString() : String Student - firstName : String - lastName : String - homeAddress : Address - schoolAddress : Address + toString() : String - streetAddress : String - city : String - state : String - zipCode : long Address

18 The this Reference The this reference allows an object to refer to itself That is, the this reference, used inside a method, refers to the object through which the method is being executed Suppose the this reference is used in a method called tryMe, which is invoked as follows: obj1.tryMe(); obj2.tryMe(); In the first invocation, the this reference refers to obj1 ; in the second it refers to obj2

19 The this reference The this reference can be used to distinguish the instance variables of a class from corresponding method parameters with the same names The constructor of the Account class (from Chapter 4) could have been written as follows: public Account (Sring name, long acctNumber, double balance) { this.name = name; this.acctNumber = acctNumber; this.balance = balance; }

20 Objects as Parameters Another important issue related to method design involves parameter passing Parameters in a Java method are passed by value A copy of the actual parameter (the value passed in) is stored into the formal parameter (in the method header) Therefore passing parameters is similar to an assignment statement When an object is passed to a method, the actual parameter and the formal parameter become aliases of each other

21 Passing Objects to Methods What a method does with a parameter may or may not have a permanent effect (outside the method) See ParameterTester.java (page 327)ParameterTester.java See ParameterModifier.java (page 329)ParameterModifier.java See Num.java (page 330)Num.java When you pass an object a copy of the address in memory is passed and any changes made to the object in the method, also change the object in the calling method.

22 public class ParameterTester{ // // Sets up three variables (one primitive and two objects) to // serve as actual parameters to the changeValues method. Prints // their values before and after calling the method. // public static void main (String[] args) { ParameterModifier modifier = new ParameterModifier(); int a1 = 111; Num a2 = new Num (222); Num a3 = new Num (333); System.out.println ("Before calling changeValues:"); System.out.println ("a1 a2 a3"); System.out.println (a1 + "\t" + a2 + "\t" + a3 + "\n"); modifier.changeValues (a1, a2, a3); System.out.println ("After calling changeValues:"); System.out.println ("a1 a2 a3"); System.out.println (a1 + "\t" + a2 + "\t" + a3 + "\n"); }}

23 public class ParameterModifier { // // Modifies the parameters, printing their values before and // after making the changes. // public void changeValues (int f1, Num f2, Num f3) { System.out.println ("Before changing the values:"); System.out.println (f1 + "\t" + f2 + "\t" + f3 + "\n"); f1 = 999; f2.setValue(888); f3 = new Num (777); System.out.println ("After changing the values:"); System.out.println (f1 + "\t" + f2 + "\t" + f3 + "\n"); }

24 Output Before calling changeValues a1 and a2 and a3 values are: a1 a2 a Before changing the values in the method change values - exactly the same: f1 f2 f After changing the values in the method, all three values are change: f1 f2 f After calling changeValues back in main a1 is the same and a2 and a3 are changed: a1 a2 a

25 Testing Testing can mean many different things It certainly includes running a completed program with various inputs It also includes any evaluation performed by human or computer to assess quality Some evaluations should occur before coding even begins The earlier we find an problem, the easier and cheaper it is to fix

26 Testing The goal of testing is to find errors As we find and fix errors, we raise our confidence that a program will perform as intended We can never really be sure that all errors have been eliminated So when do we stop testing? Conceptual answer: Never Snide answer: When we run out of time Better answer: When we are willing to risk that an undiscovered error still exists