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!