Section 7 overwrite virtual Interfaces
Sometimes we need to express an abstract thing. It is a generalization of something, but we cannot really see it as an entity before our eyes, therefore, the object-oriented programming language has the concept of abstract classes. C # As an object-oriented language, the concept of abstract classes must also be introduced. Interfaces and abstract classes allow you to create a definition of component interaction. Through the interface, you can specify the methods required by the component, but do not actually specify how to implement the method. Abstract classes allow you to create behavior definitions and provide some common implementations for inheriting classes. Interfaces and abstract classes are useful tools for implementing polymorphism in components.
An abstract class must provide an implementation program for all the members of the interfaces listed in the basic class list of the class. However, an abstract class is allowed to map interface methods to abstract methods. For example
Interface IMethods {
Void F ();
Void G ();
}
Abstract class C: IMethods
{
Public abstract void F ();
Public abstract void G ();
}
Here, the IMethods implementation functions map F and G to the abstract method, and they must be overwritten in a non-abstract class derived from C.
Note that the explicit interface member implementation function cannot be abstract, but the explicit interface member implementation function can certainly call the abstract method. For example
Interface IMethods
{
Void F ();
Void G ();
}
Abstract class C: IMethods
{
Void IMethods. F () {FF ();}
Void IMethods. G () {GG ();}
Protected abstract void FF ();
Protected abstract void GG ();
}
Here, the non-abstract classes derived from C must overwrite FF and GG, so the actual implementation program of IMethods is provided.