Basic knowledge of C #: Basics (9) interface application

Source: Internet
Author: User
Prior to the concept of contact interface, in fact, the interface is a set of methods, properties, and then who inherited it, who will implement this set of methods and properties. That is to say, this class has some of the capabilities of this interface definition.
This feature of the interface is very useful in routine programming, and often it takes a lot of people to complete a large project, so there will inevitably be some classes that require some method, and the execution process is similar. It is necessary in the project design phase to abstract this approach to an interface, and then in the project, you only need to implement this interface, so as to prevent everyone because of their respective definitions, resulting in the same operation is more chaotic.
For example, in a desktop application, a lot of windows will be used, the window will register the event (which is generally used for different control of event delivery), but also paste the skin (that is, take the picture as a form and the control on the form background picture), and so on, which is required for each window method. Like this you can abstract an interface, the name of:
Iwindowadditionalable.
For example, the interface is implemented when the Useform window is written:

Interface:

    Interface iwindowadditionalable    {        void Pasteskin ();//Paste skin void registerevent () to the controls in the form        ;//Register the event to use    }

Implement the interface code:

Public partial class Useform:form, iwindowadditionalable//each write a form class implements the interface    {public        useform ()        {            InitializeComponent ();            Pasteskin ();            Registerevent ();        }        #region Iwindowadditionalable members///<summary>/////        </summary> public        void Pasteskin ()        {            this.btnTest.BackColor = Color.gray;        }        <summary>        ////Registration Event Method///</summary> public void registerevent ()        {            This.btnTest.Click + = new EventHandler (btnTest_Click);        }        void btnTest_Click (object sender, EventArgs e)        {            throw new notimplementedexception ();        }        #endregion    }

In other Windows A, B ... When the interface is implemented, it is more uniform and does not fall into one method. It is also possible to write some other interfaces that meet certain requirements, depending on the needs of the project.

The above is the basic knowledge of C #: Basic Knowledge (9) interface application content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.