Abstract classes and interfaces Similarities: (1) can be inherited (2) cannot be instantiated (3) can contain method declarations (4) The derived class must implement the unimplemented method Category: (1) Abstract base classes can define fields, properties, and method implementations. Interfaces can only define attributes, indexers, events, and method declarations, and cannot contain fields. (2) An abstract class is an incomplete class that needs further refinement, while an interface is a behavioral norm. Microsoft's custom interfaces always come with an able field to prove that they are expressions of the "I can do it..." ” (3) Interfaces can be implemented multiple times, and abstract classes can only be inherited by a single person (4) Abstract classes are more defined between a series of closely related classes, while most of the interfaces are loosely related classes that all implement a certain function (5) Abstract classes are concepts abstracted from a series of related objects, so they reflect the internal commonality of things; An interface is a functional convention defined to satisfy external calls, so it reflects the external characteristics of things (6) The interface basically does not have any specific characteristics of inheritance, it only promises methods that can be called (7) Interfaces can be used to support callbacks, but inheritance does not have this feature (8) The specific methods implemented by abstract classes are virtual by default, but the interface methods in the class that implement the interface are non-virtual by default, of course, you can also declare them virtual (9) If an abstract class implements an interface, the method in the interface can be mapped to the abstract class as an abstract method without having to implement it, and the method in the interface can be implemented in a subclass of the abstract class
|