Software Design Methodologies: UML in Action Dr. Mohamed Fayad, J.D. Edwards Professor Department of Computer Science & Engineering University of Nebraska, Lincoln Ferguson Hall, P.O. Box 880115 Lincoln, NE 68588-0115 http://www.cse.unl.edu/~fayad May-June 2001 ISISTAN Research Institute – Tandil, Argentina Lesson 11: Object-Oriented Concepts -2 2 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S2 OO Concepts -2 Lesson Objectives Review of previous lecture Discuss associations Explore recursive associations, attributed association Understand association constraints Understand qualified & derived associations Discuss UML – aggregation Objectives 3 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S3 OO Concepts -2 Associations An association shows a two-way relationship between objects (instances) of two or more classes and requiring special implementation to ensure integrity. A particular instance of an association is often called a link. Associations between classes are required if the objects need to communicate. Associations are often named, and have role-names for each side of the link. 11 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S4 OO Concepts -2 More on Associations Association Name Car model year # of doors Person Vehicle Registration registeredCar owner name age address Roles Names 5 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S5 OO Concepts -2 More on Associations Simple example: Window displays 0..* GeomFigure An association has a name and a numerical specification (multiplicity indication) of how many objects on one side of the association are connected with how many objects on the other side. Associations are called use relationships – even if this may seem somewhat cheeky in the example below Company employs Employer May-June 2001 0..* Person Employee ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S6 6 OO Concepts -2 More on Associations Associations are directed (one way), bidirectional, and undirected. UML makes no distinction between bidirectional and undirected associations. Multiplicity Class1 1 role1 May-June 2001 Stereotype RelationName {Constraints} * Class2 Role2: interface ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S7 7 OO Concepts -2 More on Associations Recursive association: A class has a relation with itself. It is also possible to model associations that are valid only temporarily “stereotype or temporary” Constraints may be used to restrict the relation under specific aspects. A role name describes how the object is seen by the opposite object in the association. An association can be described in more detail by means of constraints, tagged values, and stereotypes. Stereotypes are noted before or above the relation name, constraints, and tagged values after or below the name. May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S8 8 OO Concepts -2 More on Associations Directed association is a one-way association, in which one side knows the other, but not vice versa. Multiplicity Specification: – 1 exactly one – 0, 1 zero or one – 0..4 between zero and four – 3, 7 either three or seven 9 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S9 OO Concepts -2 More on Associations More multiplicity specifications: – 0..* greater than or equal to zero (default) – * ditto – 1..* greater than or equal to one – 0..3, 7, 9..* between zero and three, or exactly seven, or greater than or equal to nine. 10 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S10 OO Concepts -2 More on Associations Recursive associations are associations in which one class is involved. has Patient Employee name staffNo roomNo manager office clerk * 1 relative * Person leads 11 reports to May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S11 OO Concepts -2 N-ary Association An n-ary association is like a common (binary) association, except that more than two association roles involved in it. N-ary association Class1 Class2 Ternary association 12 Class3 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S12 OO Concepts -2 More on n-ary Association Reservation Train date trainNo 1..* 1 Seat carriageNo seatNo 1..* Passenger name title May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad Ternary association L11-S13 13 OO Concepts -2 More on Associations • Recursive Associations • N-ary Associations • Attributed Associations (Association Class) • Association Constraints • Qualified Associations • Derived Associations • Directed Associations • Ordered Associations • Realization/Refinements • Dependency May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S14 14 OO Concepts -2 More on Associations Associations are usually bidirectional Allows each object involved in the relationship to refer to the object to which it is related. Bidirectional association means at the relationship has an inverse. Associations do not have to be bidirectional. May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S15 15 OO Concepts -2 Man Woman Marriage husband Screen wife Association Type One-to-One Window Windows One-to-Many (One-to-Zero-or-More) Nets Authorization User Many-to-Many Car Trailer Zero or One May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S16 16 OO Concepts -2 Association Type Square Line Sides Specified the # of instances on the “many” side Secure Room Male Person Occupants TraditionalFamily father mother Female Specify the possible # of instances using “or” Ternary relationship children Child May-June 2001 17 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S17 OO Concepts -2 Association Class Server Connection Client Connection baudRate protocol wireType disconnect rerouteLink • These attributes don’t belong in either the Client or Server class. • They are attributes of the connection itself. • The association class can have behaviors as well as attributes. May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S18 18 OO Concepts -2 Aggregation & Composite Aggregation is a special form of association. Aggregation is used when the relationship is “part/whole” or “contains/is-part-of” Aggregation is transitive and operations on “whole” often cascade down to “parts”. 19 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S19 OO Concepts -2 Aggregation & Composite Server Aggregation Computer “whole” 52 “part” Client * CPU Disk Drive Keyboard Mouse 20 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S20 OO Concepts -2 Aggregation & Composite Special diamond symbol used on “whole” side to indicate aggregation. Aggregation is an anti-symmetric that is, if A is part of B, then B is not part of A. DO NOT confuse aggregation with generalization An essential property of aggregates is that the whole acts as a proxy for its parts. A composition is a strict form of aggregation, in which the parts are existence-dependent on the entirely May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S21 21 OO Concepts -2 Aggregation & Composite Aggregation Part Entirely Composition ExistenceDependentPart 22 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S22 OO Concepts -2 Aggregation Problem Mr. Clinton’s hand is part-of Mr. Clinton & Mr. Clinton is part-of U.S.A. May-June 2001 Therefore: Mr. Clinton’s hand is part-of U.S.A. ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S23 23 OO Concepts -2 Keypad Cash Register Example * Number Keys Total Key display Subtotal Key display display drawer Drawer Display 24 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S24 OO Concepts -2 Aggregation vs. Inheritance Aggregation Inheritance Instances of distinct classes Instances of a single class “a-part-of” “a-kind-of” or “is-a” (AKO) (APO) Contains superclass-of Aggregate + parts Superclass + subclass “and” relationship “or” relationship Propagated only if specified Inheritance May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad 25 L11-S25 OO Concepts -2 Discussion Questions May-June 2001 • What is an association? Give examples • Associations are usually bidirectional. Please describe. • Describe the basic difference between aggregation and inheritance. What do they have in common? • What do you think “multiple inheritance” means? • Which type of association is more likely to yield savings in the amount of code required for implementation? why? • Define the process of identifying objects, classes, inheritance, associations & aggregation, attributes, and behaviors • Define Polymorphism with examples • What do we mean by saying “Model/View/Controller”? ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S26 26 OO Concepts -2 Questions for the Next Lecture Define: – Use Case – Structured English What are the good, bad, and ugly of Use Case? 27 May-June 2001 ISISTAN Research Institute – Tandil, Argentina -- M.E. Fayad L11-S27 OO Concepts -2