Also, let's talk about the differences between abstract classes and interfaces.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.