2Classes have similar features.Create a superclass for the two classes and move the same features to the superclass.
Motivation: RepetitionCodeIs one of the worst in the system. If you do the same thing in different places, once you need to modify those actions, you have to make more changes in plain white.
Some form of repeated code is: two classes do similar things in the same way, Or do similar things in different ways. Objects provide a mechanism to simplify this situation, that is, inheritance. However, before creating these generic classes, you often cannot find such a common class. Therefore, after the common classes appear, you often start to establish the inheritance structure.
Another option is extract class (extraction class ). The choice between the two schemes is actually the choice between inheritance and delegation. If two classes can share behaviors or interfaces, inheritance is simple. If you choose the wrong one, there will always be replace inheritance with delegation (replace inheritance with Commission) this bottle of regret medicine can be taken.