Drawback of Composition

As we saw in the previous snippet, we are creating an object of the Salary class inside EmployeeOne class which has no relation to it. So from the outside, if we delete the object of EmployeeOne class i.e emp in this case, then the object of Salary class i.e obj_salary will also be deleted because it completely depends upon the EmployeeOne class and its objects. To solve this dependency problem, Aggregation came into the picture. 

Python OOPS – Aggregation and Composition

In this article, we will compare and highlight the features of aggregation and Composition in Python OOPS.

 

Similar Reads

Concept of Inheritance

Inheritance is a mechanism that allows us to take all of the properties of another class and apply them to our own. The parent class is the one from which the attributes and functions are derived (also called as Base Class). Child Class refers to a class that uses the properties of another class (also known as a Derived class). An Is-A Relation is another name for inheritance....

Concept of Composition

Composition is a type of Aggregation in which two entities are extremely reliant on one another....

Concept of Aggregation

...

Drawback of Composition

Aggregation is a concept in which an object of one class can own or access another independent object of another class....

Why we should use Aggregation over Composition?

...

Contact Us