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.
Contact Us