Posts

Showing posts from November, 2020

aggregation vs composition

Image
Aggregation (collection) differs from ordinary composition in that it does not imply ownership. In composition, when the owning object is destroyed, so are the contained objects. In aggregation, this is not necessarily true Composition (mixture) is a way to combine simple objects or data types into more complex ones. Compositions are a critical building block of many basic data structures Both denotes relationship between object and only differ in their strength. UML notations for different kind of dependency between two classes Composition : Since Engine is part-of Car, relationship between them is Composition. Here is how they are implemented between Java classes.   public class Car { //final will make sure engine is initialized private final Engine engine; public Car(){ engine = new Engine(); } } class Engine { private String type; } Aggregation   : Since Organization has Person as employees, relationship between them is Aggregation. Here is how they