Reputation: 1232
I am bit confused so if you can enlighten me please.
Upvotes: 2
Views: 506
Reputation: 4597
Composition vs. Aggregation has to do with component object lifetime, not how the component objects are instantiated. If component objects are disposed of when the containing object is disposed of, it's Composition. If the component objects can live on, it's Aggregation.
Upvotes: 3
Reputation: 37719
The term "composition" has slightly different meaning within UML and OOP.
In UML, composition is a stronger form of aggregation and is sort of like a "owns-a" association.
The GoF design pattern book suggests that in OOP, one should favor composition over inheritance. In this case, composition just means that functionality is provided by referencing a class rather than inheriting from it.
It seems that you have some terms mixed up. Creating and object or calling a factory method is not in itself composition.
Upvotes: 2