C # Interface Basics Tutorial Seven overlay virtual interfaces

Source: Internet
Author: User

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

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.