Previously, I have been familiar with the concept of an interface. In fact, an interface is a set of methods and attributes. Whoever inherits it will implement this set of methods and attributes. That is to say, this class has some ability to define this interface.
This feature of interfaces plays a major role in programming. It often requires many people to complete a large project at the same time. In this way, some classes need some methods, the execution process is similar. This is why it is necessary to abstract this method into an interface during the project design stage. Then, in the project, you only need to implement this interface to prevent everyone from defining their own interfaces, the same operation is confusing.
For example, many windows are used for desktop applications, and events are registered in Windows (this is generally used for event transfer between different controls ), it also sticks to the skin (that is, taking the image as the background image of the controls on the form and form), and so on. This is the method required for every window. In this way, you can abstract an interface with a name:
Iwindowadditionalable.
For example, this interface is implemented when the useform window is written:
Interface:
Interface iwindowadditionalable {void pasteskin (); // paste void registerevent () to the control in the form; // register the event to be used}
Implementation interface code:
Public partial class useform: form, iwindowadditionalable // This interface is implemented for each form class written {public useform () {initializecomponent (); pasteskin (); registerevent ();} # region iwindowadditionalable member /// <summary> // method of skin pasting /// </Summary> Public void pasteskin () {This. btntest. backcolor = color. gray;} // <summary> // Method for event registration /// </Summary> Public void registerevent () {This. btntest. click + = new eventhandler (btntest_click);} void btntest_click (Object sender, eventargs e) {Throw new notimplementedexception ();} # endregion}
This interface is implemented in other Windows A, B..., so that it is more unified, and no method will be dropped. Of course, you can also write some other interfaces that meet certain requirements based on different project requirements.