What is the difference between an interface and an abstract class
What is the basis of your choice to use interfaces and abstract classes?
The concepts of interfaces and abstract classes are different. An interface is an abstraction of an action, and an abstract class is an abstraction of the root.
The abstract class represents what this object is. The interface represents what this object can do. For example, men, women, these two classes (if it's a class ...) ), their abstract class is human. Description, they are all human.
People can eat, dogs can eat, you can define "eat" as an interface, and then let these classes to implement it.
Therefore, in high-level languages, a class can inherit only one class (abstract class) (just as people cannot be both biological and non-living), but can implement multiple interfaces (eating interfaces, walking interfaces).
1th. An interface is a variant of an abstract class, and all methods in an interface are abstract. Abstract classes are classes that declare the existence of a method without implementing it.
2nd. Interfaces can inherit multiple, abstract class not
3rd. An interface definition method cannot be implemented, whereas an abstract class can implement a partial method.
4th. The basic data type in the interface is static and the suction class is not.
When you focus on the nature of a thing, use an abstract class, and when you focus on an operation, use an interface.
Abstract classes are much more powerful than interfaces, but the cost of defining abstract classes is high. Because of the high-level language (which is actually designed), each class can inherit only one class. In this class, you must inherit or write all of its subclasses.
All commonalities. Although the interface is much weaker in functionality, it is only a description of an action. And you can implement multiple interfaces in one class at the same time. In the design phase will reduce the difficulty.
What is the difference between a switch interface and an abstract class