Association Relationships Flashcards
(11 cards)
What is an association?
The relationship between two objects
Composition
A type of association represented by a filled diamond in which a whole relationship occurs. Eg An engine is a part of a car
Aggregation
A type of association represented by a non filled diamond. This is a relationship in which another class holds a collection of instances of another class. Eg a buyer may have a cart which is a collection of products (Buyer has products)
Benefits of associations
Control visibility of other object to client classes and reuse what we need
Client object can communicate with engine but not a piston
If we need to change anything in the piston class, the car class may need to change but not the client class.
Inheritance vs Composition
Composition is done at runtime with dynamic binding ie type of object not determined until runtime
Whereas inheritance is done at compile time through static binding. (type of object is fixed at compile time)
What are Association classes?
Allow you to add attributes operations and state to associations
Person -> Employed by -> Company
Instead of storing their employee data in the person class, it can be stored in an employee class
Benefit of Association classes
There can only be one instance of the association class between two participating objects
What is a self association/reflexive association?
if the same class appears twice in an association, the two instances do not have to be the same object. Eg someone may have a friend association with another person
What does a Qualifier do?
Distinguishes the set of objects at the far end of the association based on the qualifier value.
Qualified association
An association with a qualifier is a qualified association. The uml equivalent of dictionaries
Example of qualified association
Publisher(Genre) -> Book