This topic is very interesting and is discussed online in many websites and blogs. As the topic headline says Composition is preferred over Inheritance, we need to understand why it is so important by identifying the problems. The better the design from the beginning of your software development, the better the maintainability and reuse.
Inheritance and Composition are two pillars of OOPs concepts. Unless they are used wisely according to your architecture, they will create problems in the future when you start adding complexity to your application.
We have already discussed Composition, now, let's discuss Inheritance before we move towards the main topic of discussion.
As the name suggests, the act of acquiring or deriving some behavior from someone is called Inheritance. In the programming world, when a certain class is inherited from another class, it creates an Inheritance. Some basic examples are written as follows:
- A car is a vehicle. The vehicle...