Java provides two mechanisms that can be used to define types that allow multiple implementations: interfaces and abstract classes. The most obvious difference between these two mechanisms is that abstract classes allow implementations of certain methods to be included,
However, the interface is not allowed. A more important difference is that, in order to implement a type defined by an abstract class, a class must be a subclass of an abstract class, that is, using the Extends keyword inheritance.
Any class, as long as it defines all the necessary methods, and adheres to the general conventions, it is allowed to implement an interface, regardless of where the class is at the class level, the interface implementation uses
Keyword implements. Because Java only allows single inheritance, abstract classes are greatly constrained as type definitions.
Existing classes can easily be updated to implement the new interface.
An interface is an ideal choice for defining mixin (mixed types).
Interfaces allow us to construct a type framework that is not hierarchically structured.
The advantage of abstract classes is that we can provide implementations for some methods, and define methods that require client-side programmers to be defined as abstractions, and those that are specifically implemented in abstract classes
Method is based on a method defined as an abstraction, that is, a concrete implementation method, simply invoking an abstract method, or invoking an abstract method after simple logic. This simplifies the client
Programmers work under pressure, not all methods like interfaces need to be implemented by the client programmer.
The advantage of interfaces is that a class can implement multiple interfaces, rather than an abstract class, inheriting only one.
Combining the advantages of the two, the introduction of Skeleton implementation Class (Abstractinterface), skeleton implementation class an abstract class, this abstract class implementation needs to implement the interface, because the skeleton abstract class is an abstract class
Can contain abstract methods, then we define the interface needs to be implemented by the client programmer method as an abstract method, and the interface is only need to invoke other abstract methods, in the skeleton
The implementation class, defined as a concrete method, provides the implementation. By combining the two, skeleton implementation classes have the advantage of interfaces and abstract classes.
In the JDK's collection framework, there are a number of such skeleton implementation classes: Abstractcollection,abstractset,abstractlist,abstractmap
18th: interface is better than abstract class