|
Answer» Composition, and Aggregation help to build (Has - A - Relationship) between classes and objects. But both are not the same in the END. Let’s understand with the help of an EXAMPLE. - CONSIDER the University as a CLASS that has some DEPARTMENTS in it. So the university will be the container object. And departments in it will contain objects. Now in this case, if the container object destroys then the contained objects will also get destroyed automatically. So here we can say that there is a strong association between the objects. So this Strong Association is called Composition.
- Now consider one more example. Suppose we have a class department and there are several professors' objects there in the department. Now if the department class is destroyed then the professor's object will become free to bind with other objects. Because container objects (Department) only hold the references of contained objects (Professor’s). So here is the weak association between the objects. And this weak association is called Aggregation.
|