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)!