Object Oriented Analysis and Design Using the UML
Object Oriented Analysis and Design Using the UML Introduction to Object Orientation PART 2 OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 1
Basic Concepts of Object Orientation w Object w Class w Attribute w Operation w Interface (Polymorphism) w Component w Package w Subsystem w Relationships OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 2
Relationships w Association § Aggregation § Composition w Dependency w Generalization w Realization OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 3
Relationships: Association w Models a semantic connection among classes Association Name Professor University Works for Association Class Role Names University Professor Employee OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 4 Employer
Relationships: Aggregation w A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts Whole Part Schedule Student Aggregation OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 5
Relationships: Composition w A form of aggregation with strong ownership and coincident lifetimes § The parts cannot survive the whole/aggregate Part Whole Schedule Student Aggregation OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 6
Association: Multiplicity and Navigation w Multiplicity defines how many objects participate in a relationships § The number of instances of one class related to ONE instance of the other class § Specified for each end of the association w Associations and aggregations are bidirectional by default, but it is often desirable to restrict navigation to one direction § If navigation is restricted, an arrowhead is added to indicate the direction of the navigation OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 7
Association: Multiplicity w Unspecified w Exactly one 1 w Zero or more (many, unlimited) 0. . * * w One or more w Zero or one w Specified range w Multiple, disjoint ranges OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 8 1. . * 0. . 1 2. . 4 2, 4. . 6
Example: Multiplicity and Navigation Multiplicity Student 1 0. . * Navigation OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 9 Schedule
Relationships: Dependency w A relationship between two model elements where a change in one may cause a change in the other w Non-structural, “using” relationship Client Class Package Supplier OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved Supplier Client Dependency relationship Client. Package Component Supplier. Package 10 Dependency relationship
Relationships: Generalization w A relationship among classes where one class shares the structure and/or behavior of one or more classes w Defines a hierarchy of abstractions in which a subclass inherits from one or more superclasses § Single inheritance § Multiple inheritance w Generalization is an “is-a-kind of” relationship OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 11
Example: Single Inheritance w One class inherits from another Ancestor Account balance name number Superclass (parent) Withdraw() Create. Statement() Generalization Relationship Subclasses Checking Savings Withdraw() Get. Interest() Withdraw() Descendents OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 12
Example: Multiple Inheritance w A class can inherit from several other classes Flying. Thing Animal multiple inheritance Airplane Helicopter Bird Wolf Horse Use multiple inheritance only when needed, and always with caution ! OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 13
What Gets Inherited? w A subclass inherits parent’s attributes, operations, and relationships w A subclass may: § Add additional attributes, operations, relationships § Redefine inherited operations (use caution!) w Common attributes, operations, and/or relationships are shown at the highest applicable level in the hierarchy Inheritance leverages the similarities among classes OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 14
Example: What Gets Inherited Ground. Vehicle Superclass (parent) weight license. Number owner 0. . * Person 1 register( ) generalization Subclass Truck Car size tonnage get. Tax( ) OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 15 Trailer
Relationships: Realization w One classifier serves as the contract that the other classifier agrees to carry out w Found between: § Interfaces and the classifiers that realize them Class Subsystem Interface Component Interface Elided form § Use cases and the collaborations that realize them Canonical form Use Case OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved Use-Case Realization 16
Class Diagram for the Sales Example Sale seller buyer Salesperson item sold Customer Corporate OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved Product Individual 19 shipping mechanism Vehicle Truck Train
2 0 From Use Cases to: Objects, Attributes, Operations (methods) - “evolutionary ” Class 1 Class 2 OOAD Using the UML - Introduction to Object Orientation, v 4. 2 Copyright Ó 1998 -1999 Rational Software, all rights reserved 20 Slide 4
- Slides: 18