Class Relationship
Class Relationship
Programming
Class Relationship
Example of Class
Sto pW atch
-seconds
+start()
+stop()
+reset()
+getSeconds(): doub le
Associations and Links
Link is physical or conceptual connection between objects
Link is an instance of an Association
Example:
Link : Susan is-wife-of Robert
Julie is-wife-of John
Association: Woman is-wife-of Man
may be implemented as
unidirectional
Implemented usually as pointers
important not to think as pointers
Associations may be
one-to-one
one-to-many
many-to-one
many-to-many
Associations Notations
Ex ac tly One
* M a ny
0 ..1Optiona l
Directed Association
*
1 ..* One Or M ore
0 ..* Ze ro Or M ore
0..* 1..*
Co mpa ny emp loyees Person
emp loys wo rksFor
Link Attributes & Association Classes
Attributes that belong to association of object rather than one object
* *
Person Company
Employment
salary:double
Role Names
Name given to either end of an association
Aggregation:
Composition:
Person Composition
brain
Aggregation
Car
Aggregation Vs. Association
Special form of Association
Confusing
Aggregation represents “part-of” relationship
Some operations on whole automatically applied to its parts
Aggregate is asymmetric : part is subordinate to the whole
Association is symmetric : objects involved are of equal stature
Inheritance
Models is-a relationship
Relationship between a class and its refined versions
Superclass or Base class
Subclass or Derived class
Inheritance is transitive
Discriminator : The property being abstracted by a particular inheritance
Breath Vs. Depth of inheritance
Inheritance Notation
Generalization
Superclass
Vehicle
+dri ve()
Subclass1 Subclass2
Ca r Tru ck
-sun Roo f
Inheritance Example
Child Animal