The eighth chapter Polymorphic
Polymorphism is the third basic feature following data abstraction and inheritance
8.1 Further discussion upward transformation
8.2 Connections
Method call binding, except that Java and final (private method belongs to the final method) all other methods are late-bound
Polymorphism is an important technique for separating changed things from unchanging things.
Do not attempt to overwrite the base class private method, but only in such a way as to produce a completely new method
The access operation of a domain is not polymorphic by the compiler, nor is the static method polymorphic
8.3 Constructors and Polymorphic
Constructor Call Order P159
If cleanup is required, the base class cleanup method is called when the subclass overrides the base-class cleanup method, after it has cleaned itself out
Try to avoid calling other methods inside the constructor (if generating polymorphism can cause positional errors)
8.4 Covariant return type
Overridden methods in an exported class can return some type of export of a base class method return type
8.5 Design with inheritance
Prioritize use of combinations rather than inheritance
Use inheritance to represent differences between behaviors, and to express changes in state with fields
Pure Inheritance (is-a) and extension (is-like-a), down transformation with runtime type recognition
Nineth Chapter Interface
Interfaces and internal classes provide us with a more structured approach to separating interfaces from implementations
9.1 Abstract classes and abstract methods
A basic form is established through an interface, which represents the common part of all exported classes
Abstract classes and abstract methods can clarify the abstraction of a class and tell the user and the compiler how to use them
9.2 interface
Interfaces are used to establish the protocol between classes
The interface domain is implicitly static and final.
Policy mode, different implementations of the delivery interface show different behavior
Adapter mode, adapting an existing implementation to a new interface
9.3 Complete Decoupling
9.4 Multiple inheritance in Java
Implementing multiple interfaces
9.5 Extending the interface through inheritance
Inheriting multiple interfaces allows the same method to be included, but only a different method of return type is indistinguishable
9.6 Adapter Interface
Getting a method to accept an interface type is a way for any class to adapt the method, which is the power of using the interface
Domains in the 9.7 interface
cannot be null, can be initialized by a very expressive expression
is not part of the interface and the value is stored in the static storage domain of the interface
9.8 Nested interfaces
9.9 Interfaces and factories
Factory Method Design Pattern
Any abstraction should be the result of real demand, and it is necessary to consider refactoring interfaces rather than adding extra levels of indirection
The appropriate principle is to prioritize the class rather than the interface, and if the requirements of the interface become very clear, then refactor
Tenth chapter Inner class
Place the definition of a class inside another class. Organize some logically related classes together and control the visibility of classes that are in-house
10.1 Creating an inner class
10.2 Connecting to an external class
The inner class automatically has access to all members of its perimeter class, and the inner class object has this reference to the Outer class object
10.3 using the. This and. New
Creating an inner class object using an external class object
10.4 Internal classes and upward transformation
10.5 Inner classes within methods and scopes
10.6 Anonymous Inner class
10.7 Nested Classes
Inner class declared as static
10.8 Why internal classes are required
The inner class provides some kind of window into the perimeter class.
Closures and callbacks, control framework
10.9 Inheritance of inner classes
10.10 Overriding of inner classes
Covering the inner class as if it were a method of the perimeter class, and it doesn't work.
10.11 local Inner class
10.12 Internal class identifier
External class plus $
Thinking in Java note three