Sometimes we need to express something abstract, it is a generalization of something, but we can not really see it become an entity before our eyes appear, this object-oriented programming language has the concept of abstract class. As an object-oriented language, C # will inevitably introduce the concept of abstract classes. Interfaces and abstract classes enable you to create definitions of component interactions. Through an interface, you can specify the methods that the component must implement, but do not actually specify how the method is implemented. Abstract classes allow you to create definitions of behaviors while providing some common implementations for inheriting classes. Interfaces and abstract classes are useful tools for implementing polymorphic behavior in components.
An abstract class must provide an implementation program for all members of the interface listed in the class's base class list. 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, IMethods's implementation functions map f and G to abstract methods, which must be overridden in non-abstract classes derived from C.
Note an explicit interface member implementation function cannot be abstract, but an explicit interface member implementation function can of course invoke an 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, non-abstract classes derived from C will overwrite FF and GG, thus providing an actual implementation of the IMethods program.
C # Interface Basics Tutorial Seven overlay virtual interfaces