1.10 interface (Interfaces)
Interface is used to define the contract of a program. With this contract, you can run the programming language restrictions (theoretically ). While the implementation Interface
The class or structure must be strictly consistent with the interface definition. The interface can contain the following members: method, attribute, index, and event. Example :*/
Interface IExample
{
String this [int index] {get; set ;}
Event EventHandler E;
Void F (int value );
String P {get; set ;}
}
Public delegate void EventHandler (object sender, Event e );
/*
The interface in the example contains an index, an event E, a method F, and a property P.
The interface supports multiple inheritance. In the following example, "IComboBox" is inherited from "ITextBox" and "IListBox" at the same time.
*/
Interface IControl
{
Void Paint ();
}
Interface ITextBox: IControl
{
Void SetText (string text );
}
Interface IListBox: IControl
{
Void SetItems (string [] items );
}
Interface IComboBox: ITextBox, IListBox {}
/*
The class and structure can be instantiated on multiple interfaces. In the following example, the class "EditBox" inherits the class "Control" and "IDataBound" and "IControl.
*/
Interface IDataBound
{
Void Bind (Binder B );
}
Public class EditBox: Control, IControl, IDataBound
{
Public void Paint ();
Public void Bind (Binder B ){...}
}
/*
In the above Code, the "Paint" method comes from the "IControl" interface; the "Bind" method comes from the "IDataBound" interface, all are implemented in the EditBox class as "public.