Differences between interfaces and abstract classes

Source: Internet
Author: User

After touching the design pattern, both the interface and the abstract class will occasionally use the limit .. But I always think the difference between the two is very subtle,

As long as the object implementing this interface can appear in any place where this type is needed... No, it cannot be expressed ..

Anyway, it is almost like the object that implements the interface, just like the object of the abstract class subclass... it can be completely replaced by the subclass object .,

1. The inherited interface must implement all its methods, while the abstract class focuses on the scalability and polymorphism when designing the abstract class. (This is used by the template method principle ),

2. I can only feel that the interface seems to be intended to abstract the function, that is, to indicate that the real user has some ability,

Abstract classes are more inclined to a family concept. The combination of abstract classes and multiple interfaces is like a single lineage, but unlimited learning ability ,,

3. for the inheritance of abstract classes, after multi-level inheritance, it is easy to produce very complex class relationships, and some Members will be more complicated. If there can be more inheritance, this situation will be even more terrible, this may also be the reason why Java abandons multi-inheritance.

We plan to analyze the design model based on the characteristics of object-oriented language ..

When is there time...

Take a rest... wait and read the book.

 

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.