1. Association
a. Aggregation: ‘has-a’ relationship: Employee has an address.
b. Composition: ‘part-of’ relationship: Engine is a part of Car
2. Inheritance: ‘type-of’ relationship : Car is a type of Vehicle
3. Realization: Implementation of some Interface
NOTE: Aggregation and Composition are sometimes confusing E.g. in examples above I have used car and engine in Composition Relationship, whereas Car and engine can also share an Aggregation as shown below:
“Swift Car has a Fiat Engine”
But the v.v.imp point here is that when we say that “Swift Car has a Fiat Engine”, the lifetime of object Fiat engine is not in hands of particular instance of ‘Swift Car’ because there might be some other car for which we can say that “Suzuki Sx4 has a Fiat Engine as well”
So the crux is that engine is a generic term here as there could be more than 1 owner/consumer
Whereas at the same time in a Composition Relationship there can’t be more than 1 owner at the same time i.e. 1 particular engine could be part of 1 car only. So if we destroy car object we can easily destroy the said instance of Engine object.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment