Beruflich Dokumente
Kultur Dokumente
Regular Loyalty
Customer Customer
Subtype1 Subtype2
-Inheritance is a required feature of object orientation
-Generalization expresses a parent/child relationship among related classes.
-Used for abstracting details in several layers
A generalisation hierarchy
Employee
Ma nager Programmer
budgetsControlled project
progLanguage
dateAppointed
6
OO Relationships: Association
0..1 *
employer teacher
Multiplicity Role
Symbol Meaning
1 One and only one Role
0..1 Zero or one “A given university groups many people;
M..N From M to N (natural language)
some act as students, others as teachers.
A given student belongs to a single
* From zero to any positive integer university; a given teacher may or may not
0..* From zero to any positive integer be working for the university at a particular
1..* From one to any positive integer time.”
Objects Association
Modeling an association between two
classes means that there is some sort of
relationship between objects of each
class that may be connected.
studies
Student Course
0..* 1..*
9
Association: Model to Implementation
* 4
Student Course
has enrolls
Class Student {
Course enrolls[4];
}
Class Course {
Student have[];
}
OO Relationships: Composition
Whole Class
Class W Association
Models the part–whole relationship
Composition
Class P1 Class P2 Also models the part–whole relationship but, in
addition, Every part may belong to only one
whole, and If the whole is deleted, so are the
Part Classes parts
[From Dr.David A. Workman]
Example Example:
A number of different chess boards: Each square
belongs to only one board. If a chess board is
thrown away, all 64 squares on that board go as well.
Figure 16.7
The McGraw-Hill Companies, 2005
OO Relationships: Aggregation
Container Class
Aggregation:
Class C expresses a relationship among instances of related
classes. It is a specific kind of Container-
AGGREGATION
Containee relationship.
Apples Milk
1 1 1 1
1 1
1 ..* 1 ..*
Exercises Soluti ons
#Problems Text
Description Diagrams
13
Aggregation vs. Composition
Composition is really a strong form of association
components have only one owner
components cannot exist independent of their owner
components live or die with their owner
e.g. Each car has an engine that can not be shared with other cars.
Aggregations
may form "part of" the association, but may not be essential to it. They
may also exist independent of the aggregate. e.g. Apples may exist
independent of the bag.
Class Modeling
(Person)
Mary Wilson
age=27
weight=121
Inheritance
Generalization
Superclass
Class Ball
Attributes Radius, Weight
Operations Throw, Catch
Subclasses
Specialization
Association and Links
Person Company
Works For
equivalent
Company Person
Employs
Employer Employee
(Person) (Company)
Works For
Johnson IBM
Association and Links
has-capital Class diagram
Country City
nam nam
e e
Canada Ottawa
France Paris
Austria Vienna
Multiplicity of Associations
Takes
6-65
Student
response
1+