interface and abstract class differences

Source: Internet
Author: User

In the past, I have not been able to distinguish between abstract classes and interfaces, of course, the syntax of the difference between the syntax we all understand, but in the real use of the time, you can be sure to use the interface or abstract class? Personally feel that this is decided by a few aspects:

① Object-oriented thinking (cognition and classification of Things)

② stands on the level of thought to differentiate between interfaces and abstract classes (nature)

③ Business Continuity Requirements

First of all, the 1th, object-oriented thinking (cognition and classification of Things). For example: Audi, you think it is a car; Boeing aircraft, you think it is a plane; if there is a flying car like a Dragon Ball, call it a rook. Do you think it's a data car or a plane? In fact, this does not have the exact answer, according to the specific business, the business or the structure of more convenient on how to divide, different classifications may come to different results. (The specific code example is then mended)

And then the 2nd, to fundamentally differentiate between interfaces and abstract classes. Abstract classes are classes that are abstractions of the same kind of things, focusing on attributes, the concept of "a". And the interface is the abstraction of the behavior, not to belong to the same kind of things, like people will move, the car will move, you can "move" abstract out as an interface, is "A can act" concept. (The specific code example is then mended)

Finally, the 3rd, the business requirement, is not the difference between an interface and an abstract class, but is used in practice to help decide whether to use an interface or abstract class. Interfaces are relatively constant, and abstract classes are changeable. (The specific code example is then mended)

  

interface and abstract class differences

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.