Chapter 9 Interface

9.1 Abstract classes and abstract methods

Java provides a mechanism called abstract methods, which are incomplete; only declarations without method bodies. abstract void f(); A class containing an abstract method is an abstract class, which must be qualified as abstract.

9.2 Interface

The interface keyword interface is used to establish an agreement between classes. All methods in an interface are public by default

9.3 Complete Decoupling

Strategy design pattern. adapter mode

9.4 Multiple inheritance in java

Multiple interfaces can be inherited separated by commas.

9.5 Extending Interfaces Through Inheritance

Interfaces can be single-inherited through extends. Try to avoid using the same name in different interfaces to avoid confusion.

9.6 Adapter interface

The common usage of interface is the strategy design pattern

9.7 Domains in Interfaces

Any fields put into an interface are automatically static and final. They are often used as constants. After javaSE5, a more powerful and flexible enum appeared.

9.7.1 Initializing fields in an interface

9.8 Nested Interfaces

An interface can be nested in a class or other interface, that is, it can be written in a class and can be written as private but cannot be upcast.

9.9 Interfaces and Factories

Interfaces are a way to achieve multiple inheritance, and the typical way to generate objects that conform to an interface is the factory method design pattern.

9.10 Summary

Any abstraction should be really required, don't blindly create interfaces and factories.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325951098&siteId=291194637