The first section
Interface (interface) is used to define an agreement of a program. The class or structure of the interface should be strictly consistent with the definition of the interface. With this agreement, you can leave the restrictions on the programming language (theoretical). The interface can be inherited from multiple base interfaces, and the class or structure can implement multiple interfaces. The interface can contain methods, attributes, events, and indexers. The interface itself does not provide the implementation of the members it defined. The interface only specifies the membership that implements the interface or interface that the interface must be provided. The interface is like a template. This template defines how objects must be implemented. The purpose is to let these methods can be referenced as an interface instance. The interface cannot be instantiated. Classs can implement multiple interfaces and are indexed by these implementations. Interface variables can only index instances of classes that implement the interface. example:
Interface iMyexample {string this [int index] {get; set;} EventHandler Even; vide; string point {get; set;}} public delegate Void EventHandler (Object Sender, Event E);
The interface in the above example contains an index this, an event Even, a method Find and a property Point.
The interface can support multiple inheritance. As in the following example, the interface "ICOMBOBOX" inherits from "ITextBox" and "IListbox".
interface IControl {void Paint ();} interface ITextBox: IControl {void SetText (string text);} interface IListBox: IControl {void SetItems (string [] items);} interface IComboBox: ITextBox, IListBox {}
Class and structure can instantiate the interface. As in the following example, class "editbox" inherits class "Control" while inheriting from "iDatabase" and "icontrol".
Interface Idatabase (Binder B); PUBLIC CLASS Editbox: Control, Icontrol, Idatabase; PUBLIC VOID (Binder B) {...}}
In the above code, the "Paint" method comes from the "iControl" interface; "Bind" method is implemented from the "iDatabase" interface and implemented in the "editbox" class as "PUBLIC".
Description:
1, the interface in the C # is defined independently of the class. This is aligned with the C model, and the interface in C is actually an abstract base class.
2, interfaces and classes can inherit multiple interfaces.
3. Category can inherit a base class, the interface does not inherit the class. This model avoids the multi-inheritance problem of C , and the implementation in different base classes in C may conflict. Therefore, this kind of complex mechanism such as virtual inheritance and explicit scope is also no longer needed. The simplified interface model of the C # helps speed up the development of the application.
4. An interface defines a reference type with abstract members. One of the interfaces in C # actually does only exist of a method mark, but there is no code at all. This suggests that you cannot instantiate an interface, you can only instantiate an object derived from the interface.
5, the interface can define methods, attributes, and indexes. Therefore, compare a class, the particularity of the interface is: When defining a class, you can derive from multiple interfaces, and you can only derive from only one class. Interface and components
The interface describes the service provided by the component. Interacting between components and components, components and customers are interacting through an interface. Therefore, once the component is released, it can only provide reasonable, consistent service by pre-defined interfaces. The stability between this interface definition allows the customer to apply developers to construct a rugged application. A component can implement multiple component interfaces, and a particular component interface can also be implemented by multiple components.
The component interface must be self-description. This means that the component interface should not depend on the specific implementation, and the implementation and interface isolation completely eliminates the coupling relationship between the user and the implementation of the interface, enhances the level of information. At the same time, this also requires the component interface to use a language that is unrelated to the component. The description criterion of the current component interface is the IDL language.
Since the interface is the protocol between components, once the interface of the assembly is released, the component producers should keep the interface as constant as possible, any changes to interface grammar or semantic changes, can cause existing components and customers. The relationship is destroyed.
Each component is autonomous, with its unique features, can only communicate with external interfaces. When a component needs to provide a new service, you can implement it by adding a new interface. Will not affect the customer already existing in the original interface. And new customers can reselect new interfaces to get services.
Componentization programming
Componentized programming methods inherit and developed object-oriented programming methods. It applies object technology to the system design, making further abstractions for the implementation of the programming of the object. We can use the components to design the components as a method of constructing the system's architecture level, and the components can be easily implemented using object-oriented methods.
Component programming emphasizes the true software reusability and height interoperability. It focuses on the generation and assembly of the components, which together constitute the core of the component manufacturing program design. The process of components is not only the needs of the application system, but the component market itself has also promoted the development of components and promoted the exchange and cooperation of software vendors. The assembly assembly allows the software product to rapidly establish a method similar to a wood, which can not only shorten the development cycle of software products, but also improve the stability and reliability of the system.
The method of component programming has the following features:
1. Programming language and independence of the development environment;
2. Transparency of the component position;
3, the process transparency of the component;
4, expandability;
5, reusability;
6, with strong infrastructure;
7. Public services at the system level;
C # language is very suitable for component programming due to its many advantages. But this is not to say that C # is a component programming language, nor does it say that C # provides components programming tools. We have repeatedly pointed out that components should have characteristics that are independent of programming language. Readers should remember this: Component model is a norm, no matter what program language design component, this specification must be observed. For example, an example of assembling a computer, as long as the various manufacturers provide us with the accessories specifications, the interface meets the unified standards, these accessories can be combined to work together, and the component programming is the same. We just say that the component programming will bring us more convenient to use the C # language.
I know what is the interface, and then how to define the interface, please see the next section - define the interface.