1 / 15

OO Design

OO Design ideas OO Design Tools & Methodologies UML, CRC Textbook (Pohl) pp.293, pp.332-335. OO Design. OO Paradigm Characteristics. Encapsulation - data + methods Information Hiding - public/private etc Message Passing - client uses class’s interface

reuel
Download Presentation

OO Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OO Design ideas OO Design Tools & Methodologies UML, CRC Textbook (Pohl) pp.293, pp.332-335 OO Design OO Programming

  2. OO Paradigm Characteristics • Encapsulation - data + methods • Information Hiding - public/private etc • Message Passing - client uses class’s interface • Late Binding- specific receiver not known until runtime • Delegation - passed up the class hierarchy • Class & Objects - instantiation • Inheritance & polymorphism - subclasses & overriding • Relationships - association & aggregation OO provides powerful tools for building large systems… How do we apply them? OO Programming

  3. Specification Design Implementation Testing Maintenance Step through these stages Iterate as necessary The Traditional Software Life Cycle OO Programming

  4. Specifications Identify all classes for each identified class do Declare it Define it Test it Integrate it Write main DDU is a repetitive design-implement-test-maintain cycles The Declare-Define-Use Approach (DDU) OO Programming

  5. DDU Example (simple) Simulation of an automatic elevator SPECIFICATIONS: • a) Input: number of riders randomly placed at random floors; floor numbers entered by keyboard • b) Output: Which floor elevator is on; direction it is heading; when riders enter and leave elevator • c) Constraints: riders may call from any floor and exit any floor; elevator is idle until called; operates until all requests completed; must board elevator when requested and and must disembark when floor is reached; no limit on number of passengers OO Programming

  6. Public: Elevator ButtonsPushed MoveToNextFloor DisplayStatus floorButtons[size ] int currentFloor Going Private: ChooseMove Create and initialize elevator Are any floor buttons pushed? Moves the elevator Tell where the elevator is One button per floor (ON / OFF) Number of floor elevator is on Direction indicator (UP / DOWN) Determine floor to move to Choose a Class ElevatorDECLARE THE CLASS ELEVATOR OO Programming

  7. Header/Declaration // ----------ELEVATE.H---------- // Declaration file for class Elevator #ifndef ELEVATE_H #define ELEVATE_H //the number of floors const int FLOORSINBLDG = 10; //possible directions for the elevator enum Direction {DOWN,UP}; … DEFINE THE CLASS ELEVATOR: write the cpp file TEST THE CLASS ELEVATOR: write int main(){ Elevator e1();… } OO Programming

  8. RULES OF THUMB for designing classes: • The nouns from the program specifications are usually implemented as classes while verbs are the functions. • When in doubt, refer to reality. • Don't be afraid to redesign your classes. • Declare member data as private and member functions as public. You can always revise your declarations later. OO Programming

  9. Design methodology… • To declare a class, we write its header file (.h). • To define a class, we write its implementation file (.cpp) • To use a class, we write a driver program that tests the class as completely as possible. • The time we spend testing classes individually will more than pay for itself when it comes to testing our complete program. • To integrate a class, we write a driver program that exercises the class in the context of other classes that refer to it. OO Programming

  10. Some Tools of OO Design • CASE (Computer assisted software engineering) has incorporated several OOD notations. • CRC (Class-Responsibility-Collaborator) note-card system is a low-tech scheme, easy to use and flexible. • The UML (Unified Modeling Language) is the most used. OO Programming

  11. Unified Modeling Language (UML) • Dietel and Dietel, “C++ How to program”, 3rd edition presents a complex Elevator simulation. • It uses 11 classes: Elevator, Clock, Scheduler, Person, Floor, Door, Building, FloorButton, ElevatorButton, Bell and Light. • The UML is used to model the classes and their relationships via diagrams. OO Programming

  12. UML Diagram for Elevator UML diagram showing: • Classes • Relationships • Ordinals See Dieter & Dieter OO Programming

  13. Class-Responsibility-Collaboration (CRC) • The responsibilities are what the object must be able to do and what the object must know (attributes and behaviours of the class). • A collaborator is another object that interacts with the given object. • Person presses button on a given floor. • An object of the Person class sends a message to an object of the button class. • Collaboration between the class Person and the class Button OO Programming

  14. Front of card: (public behaviour) Classname: Person Responsibility: ID, exitElevator, enterElevator,... Collaborators: person sends pushButton message to the FloorButton object, ... Back of card: (implementation details) ID : int exitElevator( ) : void enterElevator( ) : void CRC cards rewritten & refined during design process OO Programming

  15. Summary • Goals of (OOD): • Identify the classes • Identify the functionality of these classes • Identify the relationships between these classes • Write clear & maintainable implementation • Not entirely trivial… OO Programming

More Related