java multi-purpose combination, less inheritance

Object-oriented principle tells us that extend the functionality of the class to be multi-purpose combination, and less inheritance. The reasons are the following:

First, the subclass inherits the parent class is all public and protected inheritance, which makes it possible subclass inherits useless or even harmful subclass the parent class. In other words, the subclass inherits only hope that part of the method of the parent class, how to do?

Second, the actual object ever-changing, if the object of each category have their own category, even though these classes inherit their parent class, but sometimes still can cause unlimited expansion of the class.

Third, inheritance subclass, in fact, need to compile finalized, this situation can not meet the needs of the object can be determined within a run. But they can be combined much more flexible than inheritance, you can only determine an object at runtime.

Guess you like

Origin www.cnblogs.com/u013533289/p/11208126.html