Differences between interfaces and abstract classes in C #

Source: Internet
Author: User
In C #, interfaces and abstract classes have many commonalities, but it may not be clear for some people who have just joined the C # team. I recently read the following statement on the Internet, it feels good. Let's share it with you:

The interface is responsible for defining functions. The project uses interfaces to define the concepts of classes, Operation classes, and abstract classes!

The class is responsible for the specific implementation of the function!

There are also abstract class definitions in the class. The difference between the abstract class and the interface is:

An abstract class is an incomplete class. The class contains abstract methods, attributes, and specific methods and attributes, which requires further specialization.

But the interface is a behavior specification, and everything in it is abstract!

A class can only inherit one base class, that is, the parent class, but multiple interfaces can be implemented.

PS: In addition to standardizing a behavior, interfaces play an important role in a specific project. In the use of object-oriented design principles and design patterns, they are all embodied as an interface.
The most direct advantage is the OCP (open and closed principle) in the design principle. We use interfaces without worrying about their specific implementation, the detailed changes in implementation are irrelevant to the client (Class Using Interfaces ).
Is open to and extended. We can write another interface implementation to expand the currentProgramBut the modification is closed, that is, we cannot modify the interface definition. Of course, this
"Not Allowed" means the rule should not be done in principle!

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.