Abstract class and interface
What is an interface: Interface is a collection of methods ------ interface is an abstract abstraction.
What is an abstract class: Abstract class is implemented for some of a specific type ------ Abstract class is the specific abstraction.
Method features include: the name of the method, the number of parameters, and the type of parameters. Does not include: return type, parameter name, and exception thrown.
The interface is the premise of type conversion is a guarantee of dynamic calls. Realize a certain interface to complete the type of conversion (multiple inheritance); dynamic calls only care about the type, do not care about the specific class.
-------------------------------------------------- -------------------------------------------------- ----------------------------------
The Java interface (abstract class) is used to declare a new type.
Java designers should mainly use interfaces and abstraction classes to couple the software unit with internal and external.
In other words, the type declaration of the Type Declaration of the Variable, the type declaration of the parameters, and the return type declaration of the data type, and the return type declaration of the method, and the transition of the data type.
Of course, a better approach is to use only interfaces instead of an abstract class to do these things.
In the ideal case, a specific class should only implement the method declared in the interface and abstract classes, and unnecessary methods should not be given!
Interfaces and abstract classes are generally the starting point for a type of grade structure.
The interface is more abstract more abstraction than the abstraction class, so the interface declares abstract type!
-------------------------------------------------- -------------------------------------------------- ----------------------------------
Abstract class and interface
The abstract class only provides a part of a class. Abstract classes can have instance variables and one or more constructor. Abstract classes can be simultaneously abstracting methods and specific methods.
An abstract class does not have an example, its constructor cannot be used to create an instance by the client. A constructor of an abstract class can be called by its subclass, so that all subclasses of an abstract class can have some common implementation, while different subclasses can have different implementations on this basis.
The interface is more abstract than the abstract class so the wired use interface declares abstract class!
The abstract class is used to inherit. (The specific class is not used to inherit, "as long as it may be inherited from specific classes - Scott Meryes").
Abstract type design principle:
1. Abstract classes should have as much code as possible! (Common Method). The code is concentrated in the abstract direction.
2, abstract classes should have as little data as possible! (Public property). Data is concentrated in the specific direction.
Inheritance multiplexing conditions ------ Peter COAD condition
1. Subclasses are a special type of superclass rather than a character! Correctly distinguish between "HAS-A" "IS-A".
2. No replacement between subclasses! ?
3. Subclasses have the responsibility of extended superclars, rather than replacement (override), or cancels the responsibility of Nullify.
4. Inheritance can only be used when there is meaningfulness in the classification point, do not inherit from specific classes.
Differences between interfaces and abstract classes:
1. Abstract classes can provide some implementation of implementation. If you add a new specific method to an abstract class, then all subclasses get this method. The interface can't do this! (This may be the unique advantage of an abstract class).
2. Because Java's single structural restrictions, only one abstract class type can only be implemented, and the interface type does not limit this limit. This makes the abstract class as the type definition tool to the interface behind the interface. The interface is an ideal tool that defines a mixed type (realize multiple inheritance). 2. From the perspective of code reconstruction, it is easier to implement a specific class from constituting an interface type.