Relationships in OOPS…
A RELATIONSHIP is what a class or an object knows about another class or object.
RELATIONSHIPS
- Class
- Generalization
- Objects
- Association
- Aggregation
- Compostition
Generalization (Class-to-Class) (superclass – subclass; supertype – subtype)
-
A Generalization follows a “is a” or “is a kind of” heuristic from a specialization class to the generalization class. (e.g., student “is a” person, video “is a kind of” inventory).
-
Common attributes, operations and relationships are located in the generalization class and are inherited by the specialization classes
-
Unique attributes, operations and relationships are located in the specialization classes.
-
Relationships between instances (objects) of classes
-
In association, Objects exists independently.
-
Conceptual:associations can have two roles (bi-directional)
-
source –> target,
-
target –> source
Aggregation
-
is a specialized form of ASSOCIATION in which a whole is related to its part(s).
-
is known as a “part of” or containment relationship and follows the “has a” heuristic
-
three ways to think about aggregations:
-
whole-parts
-
container-contents
- group-members
-
is a stronger version of AGGREGATION
-
the “part(s)” may belong to only ONE whole
- the part(s) are usually expected to “live” and “die” with the whole (“cascading delete”)