Presentation is loading. Please wait.

Presentation is loading. Please wait.

240 3/30/98 CSE 143 Object-Oriented Design [Chapter 10]

Similar presentations


Presentation on theme: "240 3/30/98 CSE 143 Object-Oriented Design [Chapter 10]"— Presentation transcript:

1 240 3/30/98 CSE 143 Object-Oriented Design [Chapter 10]

2 241 3/30/98 Design Process  The traditional development model consists of three phases:  Analysis - defining the problem (what)  Design - the solution (high level)  Implementation - the solution (code)  Traditional development is sometimes called the waterfall model. Analysis DesignImplementation

3 242 3/30/98 Traditional Development  In this course, the problem is usually pretty well defined. We often suggest a design and ask you to provide an implementation.  Most of the time, development isn’t so easy…  Analysis or design may be poor  Goals may change during development  Implementation may be too hard or take too long  Testing?  Social, political, economic factors

4 243 3/30/98 Design Methodology  Changes may result in lots of wasted work! How to minimize their impact?  Use a good design methodology  Procedure and structure by which a design is created  Top-Down Design, aka structured design  Focus on overall control flow rather than data.  Think of problem in terms of functions and algorithms and how they need to interact  Often have a layered or hierarchical approach: make successively more detailed refinements to design

5 244 3/30/98 Top-Down Design  Advantages and disadvantages?  Usually gives very structured approach to problem First input is read, then processed, then results are printed, etc.  Adapts well to analysis, design, implementation phases  If right breakdown is chosen, everything works OK Each function does one thing and is separated from others  What happens if a bad decision was made? Not easy to fix without rewriting a lot of code  What happens if design needs to be changed?

6 245 3/30/98 Problems and alternatives  The traditional design model has shown itself to be insufficient for many real world tasks  cf. C-17, Air Traffic Control System  Alternatives:  Iterative software development models  rapid prototyping, exploratory programming (requires higher-level programming languages)  participatory design  object-oriented design  Need to involve the user early in the process.

7 246 3/30/98 Object-Oriented Design  Alternate design philosophy.  Instead of control flow, concentrate on entities (“objects”) in the problem (data-driven approach)  Object = Collection of data and operations on that data  All phases of design are in terms of objects  Lends consistency across phases without arbitrary breakdown between ideas and implementations  More relaxed, iterative, three-phase approach:  Can prototype a design or implementation and adapt it to changing needs relatively easily (true?)

8 247 3/30/98 OO Design (2)  What about changes?  Should be localized to a single object, or operations of objects, not spread out across lots of functions  What about bad decisions?  Hopefully, changes will be restricted to objects instead of functions  Ideally, objects are more reasonable way to think about problem than “flow control” is  Which approach is better?  Depends on the problem, the people, etc...

9 248 3/30/98 Designing in the OO Style  Identify the objects in the problem, and the operations they should have  What are the objects in the problem?  Determine organization of objects and operations  How do the objects relate to one another?  Are some contained inside another object, or need to organize other objects?  Drawing an object hierarchy diagram might help  Design a driver  Implement objects (C++ classes, or off-the-shelf)  Test and refine

10 249 3/30/98 What is an object?  Metaphor: robot, daemon  In C++  A class instance  A variable of a built-in type  Examples: ItemList I; int c; Bus b;// traffic simulation DieselBus d; ElectricBus e; DualModeBus f;

11 250 3/30/98 What is an operation?  Metaphor: a message which is sent to an object, requesting an action or service  Any action that manipulates data  Examples: i++; // built-in operation list.insertItem(...); // member function strcmp(a, b); // global function

12 251 3/30/98 Objects and operations  From the problem statement:  nouns may suggest objects  verbs (and often adjectives) may suggest operations  Determining which nouns and verbs are important is difficult  Examples of nouns from a bank simulation: bank, customer, account, accountNumber, balance, name, etc.  Example verbs: balance, deposit, withdraw, has, close  Adjectives: overdrawn

13 252 3/30/98 Object - Bank  Characteristics  name  list of customers  list of accounts  Operations  open an account  get the balance of an account  deposit money into an account

14 253 3/30/98 Object - Account  Characteristics  account number  type  balance  Operations  open  close  get balance  deposit

15 254 3/30/98 Organizing the objects  Relationships among the objects  has-a relationship (e.g. a customer has a name)  part-of relationship (e.g. an account number is part of the account)  Why do we need to determine the relationsips?  Leads to natural ways to implement the design  Suggest where to place the operations

16 255 3/30/98 Placing the operations  Who is responsible for this operation: Deposit an amount into an account.  Account (object)  Amount (object)  Deposit (operation)  Compare these calls: account.deposit(amount); amount.deposit(account); deposit(account, amount);  Which is better? If you can’t assign primary responsibility, the function is probably global.

17 256 3/30/98 The Driver  In a well designed program, the driver (main) is the easiest part to write.  The driver program should do little more than process user commands and delegate tasks to the objects.

18 257 3/30/98 Summary  Object-oriented design typically results in layered software.  ADTs play a vital role in these layers of abstraction.  OO design helps in problem decomposition and aids in reuse.  Still to consider:  inheritance  polymorphism


Download ppt "240 3/30/98 CSE 143 Object-Oriented Design [Chapter 10]"

Similar presentations


Ads by Google