A: Introduction of reusable functions
The reuse of code, in addition to copying and changing the code is not enough, in addition to the ability to use the class without breaking the existing program code.
Code reuse in Java can be divided into the following three categories: combination, inheritance, proxy.
Two: Combination
The new class uses an object from an existing class, and the new class consists of an object of an existing class.
Three: Inheritance
Declaration is implemented by extends syntax.
Four: Agent
Java does not provide direct support to the agent, but by combining and inheriting the indirect implementation, the broker is the middle of the combination and inheritance. Agent = inheritance + combination
Specific understanding can refer to the relevant code!
Five: base class method Quilt class overloading
A subclass overloads a method of a parent class and does not block any version of it in the base class, so the overloaded mechanism can execute normally regardless of the method definition in that layer or its base class.
Six: Re-discussion on combination and inheritance
Emphasizing inheritance does not mean that we want to use inheritance as much as possible, instead we should use inheritance with caution. One of the clearest ways to determine whether to use inheritance or use a combination is to ask yourself if you need to move up from a new class to a base class.
Java Programming thought Note (iii)-Reuse of classes