This article is a mirror article of machine translation, please click here to jump to the original article.

View: 20706|Reply: 0

[Source] C# Difference between abstract classes and interfaces

[Copy link]
Posted on 6/21/2016 11:34:25 AM | | |
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








Previous:System error 5 has occurred. Access is denied.
Next:The 'Microsoft.Jet.OleDb.4.0' provider is not registered on the local machine.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com