Association,Aggregation and Composition is a core concepts of oop about the relationship of different classes with slightly difference in each other.
Association: The two Classes has a relationship with each
other but each class has its own life cycle and not rely on each other
for example class “A” may has multiple or single object of class “B” and Class “B” may also has multiple or single objects of class “A”.
for example class “A” may has multiple or single object of class “B” and Class “B” may also has multiple or single objects of class “A”.
Example: student has one or different departments and one department have one
or more students and not depend on each other.
Aggregation: Aggregation is a special type of Association means each entity has
its own life cycle but one of them rely on other
means class “A” has only single object of class “B” at a time but class “B” has multiple or single objects of class ”A”.
means class “A” has only single object of class “B” at a time but class “B” has multiple or single objects of class ”A”.
Example: Employee has only one company at a time and company may have one or
multiple employees but both has different life cycle.
Composition: Composition is a special type of Aggregation means one entity of
them rely on other i.e. class “A” has
only single object
of class “B” at a time but class “B” has multiple or single objects of class “A”
but when one entity destroy other also must destroy means one life cycle is depend on other.
of class “B” at a time but class “B” has multiple or single objects of class “A”
but when one entity destroy other also must destroy means one life cycle is depend on other.
Example: Room has only one house but house may have one or multiple rooms
but room has no existent without house so room life cycle depends on house.
but room has no existent without house so room life cycle depends on house.
Happy Coding :)
i sorry for explaining this, hope you do not mind it.
ReplyDelete1-Nice article but lake of class coding example.
2-this article must be explained using one of pattern (this is my thought).
e.g. example should be elaborated by using of strategy or decorator pattern