Reading directory
I. Preface
Ii. What is the difference between interfaces and abstract classes?
I. Preface
In object-oriented programming, abstraction is an agreement that the successor or implementer must follow. For example, if a class inherits or implements an interface, the class must implement all the members of the interface, an interface is an abstraction of A Class. A Class must follow the protocol of all its members.
Ii. What is the difference between interfaces and abstract classes?
Interfaces and abstract types are two mechanisms used to implement abstraction in Object-Oriented Programming. So when can I use interfaces to implement abstraction in object-oriented programming? Under what circumstances can abstract be implemented using abstract types?
1: The interface cannot provide implementation details of members, but the abstract type can provide implementation details of members. That is to say, all methods in the interface must be abstract, as shown in the following InserUser () and IGetName (), and the access modifier of the method cannot be specified, but there can be method implementation in the abstract type. For example, the following GetName () can also specify the access modifier public, if you need to provide implementation details for Members during design, select the abstract type.
Interface
Interface Interface1
{
Void IInserUser ();
String IGetName ();
}
Abstract type
Public abstract class Class1
{
Public abstract void InserUser ();
Public virtual string GetName ()
{
If (2 = 2)
Return "getting sleepy from an early age ";
}
}
2: in C #, classes and classes are single-inherited. A class can only inherit from one abstract class, while a class can inherit multiple interfaces, if you want to implement multi-inheritance during design, select the interface