Advantages and disadvantages of Inheritance
Advantages
New implementations are easy, because most of them are inherited.
It is easy to modify and extend existing implementations.
Disadvantages
The encapsulation is broken because the basic class exposes implementation details to the subclass.
White box reuse, because the internal details of the base class are usually visible to the subclass.
When the implementation of the parent class changes, the subclass may be changed accordingly.
The implementation inherited by the parent class cannot be changed at runtime.
It can be seen that the combination has more flexibility and more stable structure than the inheritance. Generally, the combination should be given priority. Only
Inheritance is considered only when the following conditions are met:
Subclass is a special type, not just a role of the parent class.
Subclass instances do not need to be converted into objects of another class.
Subclass extension, instead of overwriting or disabling the function of the parent class