A friend posted a blog post titled "html"> what is the difference between abstract classes and interfaces that you don't understand, I don't think the content of my blog is a good explanation of the title "The difference between abstract classes and interfaces that you don't understand.
Let me talk about my opinion.
Let's give an example to help you understand it, And then abstract and summarize the theory from the example.
For example, a manufacturer needs to define a door template to quickly produce various types of doors.
There are usually two types of templates: abstract class templates and interface templates.
Abstract class template: This template should contain the common attributes (such as the shape and color of the door) and common behaviors (such as opening and closing) of all doors ).
Interface Template: Some doors may need functions such as alarm and fingerprint recognition, but these functions are not mandatory for all doors, so such behavior should be placed in a separate interface.
With the above two types of templates, the production door will be very convenient in the future: using the abstract class template and the interface template that contains the alarm function can produce the door with the alarm function. Similarly, the abstract class template and the interface template that contains the fingerprint recognition function can be used to generate a door with the fingerprint recognition function.
Abstract classes are used to abstract objects with similar properties and behaviors in nature. Interfaces are used to abstract the standards and norms of behavior, and are used to tell the interface implementers to complete a function according to certain specifications.
This is my opinion. You are welcome to discuss this issue with me.