Posts

COMPOSITION

Image
  The composition  is an association that represents a part of a whole relationship where a part cannot exist without a whole. If a whole is deleted then all parts are deleted. It has a stronger relationship. Key Points It represents a part-of relationship. In composition, both the entities are dependent on each other. When there is a composition between two entities, the composed object cannot exist without the other entity. For example, if order HAS-A line-items, then an order is a whole and line items are parts If an order is deleted then all corresponding line items for that order should be deleted.  Favor Composition over Inheritance. Program Example of Java Composition Let us consider the following program that demonstrates the concept of composition. Step 1: First we create a class Bike in which we declare and define data members and methods: class Bike { // declaring data members and methods private String color; private int wheels; public void bikeFeatures() { System.out