4 Basic Structural Modeling Relationships Overview Relationships Dependency
4. Basic Structural Modeling Relationships
Overview • Relationships – Dependency – Generalization – Association • Modeling techniques • Building webs of relationships Sung Kim CS 6359 Slide 2
Relationships Window Event open() close() dependency generalization Console. Window Dialog. Box Control association Sung Kim CS 6359 Slide 3
Dependency • Dependency—a change in specification of one thing may affect another. • “Uses” relationship. • May have a name, but not common. Film. Clip name Channel play. On(c: Channel) start() stop() Sung Kim dependency CS 6359 Slide 4
Generalization • Generalization—relationship between general thing (parent) and specific kind of thing (child) • Child “is-a-kind-of” parent. • Child inherits attributes and operations of parent. generalization Rectangle Circle Polygon leaf class Square Sung Kim base class Shape CS 6359 Slide 5
Generalization (cont’d) • May have a name, but not common. • Polymorphism—multiple objects can respond to the same message in different ways. – Achieved through generalization and interfaces. – Children of the same parent are polymorphic. Sung Kim CS 6359 Slide 6
Association • Association—structural relationship where objects of one class are connected to objects of another class. • Navigation is bi-directional by default. • Binary association connects exactly two classes. N-ary connects many classes. Sung Kim CS 6359 Slide 7
Association Adornments • Name—descriptive term for the association. • Role—persona the class at the near end of the association presents to the class at the other end of the association. • Multiplicity—defines the number of objects associated with an instance of the association. – Default of 1 – Zero or more (*) – n. . m; range from n to m inclusive • Aggregation—structural association representing “whole/part” relationship; “has-a” relationship. Sung Kim CS 6359 Slide 8
Association Representation multiplicity association name Person works for 1. . * * employee employer Company association roles Sung Kim CS 6359 Slide 9
Aggregation Representation multiplicity Department 1. . * whole Company part association Sung Kim CS 6359 aggregation Slide 10
Modeling Techniques • Simple dependencies • Single inheritance • Structural relationships Sung Kim CS 6359 Slide 11
Modeling Simple Dependencies • One class uses another as a parameter to an operation. – Create dependency pointing from class with operation to parameter. Course. Schedule Course add(c: Course) remove(c: Course) Sung Kim CS 6359 Slide 12
Modeling Single Inheritance • Be careful! Inheritance is too often abused. • Look for common responsibilities, attributes, and operations. • If necessary, create a new class to assign commonalities. • Specify that the more-specific classes inherit from the more-general. Sung Kim CS 6359 Slide 13
Modeling Inheritance (cont’d) • Abstract – – Abstraction—the essential characteristics of a thing. Abstract class—cannot be instantiated. Abstract method—has no implementation defined. Depicted in italics or with stereotypes. • Concrete – Not abstract. – Can have instances. Sung Kim CS 6359 Slide 14
Modeling Inheritance (cont’d) Security abstract present. Value() history() Cash. Account Stock Bond present. Value() interest. Rate present. Value() Preferred. Stock Sung Kim Common. Stock CS 6359 Slide 15
Modeling Structural Relationships • Specify an association to create a navigation path between two objects. • Specify an association if two objects interact with each other beyond operation arguments. • Specify multiplicity; 1 is assumed. Error in text on implicit default. • Specify aggregation when one of the classes represents a whole over the other classes. Sung Kim CS 6359 Slide 16
Web of Relationships Example Sung Kim CS 6359 Slide 17
Hints & Tips • Modeling relationships – – Use dependencies when relationship is not structural. Use generalization with “is-a” relationship. Don’t introduce cyclical generalizations. Balance generalizations • Not too deep • Not too wide – Use associations where structural relationships exist. Sung Kim CS 6359 Slide 18
Hints & Tips (cont. ) • Drawing a UML relationship – Use rectilinear or oblique lines consistently. – Avoid lines that cross. – Show only relationships necessary to understand a particular grouping of things. – Elide redundant associations. Sung Kim CS 6359 Slide 19
Summary • Relationships – Dependency – Generalization – Association • Modeling techniques Sung Kim CS 6359 Slide 20
4. Advanced Structural Modeling Advanced Relationships
Overview • Advanced Concepts on: – Dependency – Generalization – Association – Realization Sung Kim CS 6359 Chapter 10 Slide 22
Advanced Relationships Controller Embedded. Agent multiple inheritance association navigation <<interface>> URLStream. Handler open. Connection() parse. URL() set. URL() to. External. Form() Set. Top. Controller authorization. Level start. Up() shut. Down() Connect() <<friend>> Channel. Iterator stereotyped dependency realization Sung Kim Power. Manager CS 6359 Chapter 10 Slide 23
Dependency • Eight Stereotypes of Dependency Among Classes – bind: the source instantiates the target template using the given actual parameters – derive: the source may be computed from the target – friend: the source is given special visibility into the target – instance. Of: the source object is an instance of the target classifier – instantiate: the source creates instances of the target Sung Kim CS 6359 Chapter 10 Slide 24
Dependency (cont’d) • Eight Stereotypes of Dependency Among Classes (cont’d) – powertype: the target is a powertype of the source; a powertype is a classifier whose objects are all the children of a given parent – refine: the source is at a finer degree of abstraction than the target – use: the semantics of the source element depends on the semantics of the public part of the target Sung Kim CS 6359 Chapter 10 Slide 25
Dependency (cont’d) • Two Stereotypes of Dependency Among Packages: – access: the source package is granted the right to reference the elements of the target package – import: a kind of access; the public contents of the target package enter the flat namespace of the source as if they had been declared in the source Sung Kim CS 6359 Chapter 10 Slide 26
Dependency (cont’d) • Two Stereotypes of Dependency Among Use Cases: – extend: the target use case extends the behavior of the source – include: the source use case explicitly incorporates the behavior of another use case at a location specified by the source Sung Kim CS 6359 Chapter 10 Slide 27
Dependency (cont’d) • Three Stereotypes of Dependency in Interactions among Objects: – become: the target is the same object as the source but at a later point in time and with possibly different values, state, or roles – call: the source operation invokes the target operation – Copy: the target object is an exact, but independent, copy of the source Sung Kim CS 6359 Chapter 10 Slide 28
Generalization • One stereotype – implementation: the child inherits the implementation of the parent but does not make public nor support its interfaces • Four Standard Constraints – complete: all children in the generalization have been specified; no more children are permitted – incomplete: not all children have been specified; additional children are permitted – disjoint: objects of the parent have no more than one of the children as a type – overlapping: objects of the parent may have more than one of the children as a type Sung Kim CS 6359 Chapter 10 Slide 29
Association • Four Basic Adornments of Association: name, role, multiplicity, & aggregation • Other Properties: –Navigation –Visibility –Qualification –Interface Specifier Sung Kim CS 6359 Chapter 10 – Composition – Association Classes – Constraints Slide 30
Realization • A realization is a semantic relationship between classifiers in which one classifier specifies a contract that another classifier guarantees to carry out. • Realization is sufficiently different from dependency, generalization, and association relationships that it is treated as a separate kind of relationship. • Semantically, realization is somewhat of a cross between dependency and generalization, and its notation is a combination of the notation for dependency and generalization. Sung Kim CS 6359 Chapter 10 Slide 31
Summary • Advanced Concepts on: – Dependency – Generalization – Association – Realization Sung Kim CS 6359 Chapter 10 Slide 32
- Slides: 32