blogs

miércoles, 17 de junio de 2015

Interface

Interface: An interface contains only the signatures of methods, properties,events or indexers. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition.

An interface can not contain constructors.
An interface only has the method signature.
An interface can not contain fields.
An interface can contain automatic property.
The modifier "Public" is not valid for methods
All methods and properties should be implemented in  classes or structs that use the interface.
The interface's access modifier is internal by default. if we want to call it in other namespace, we need change it to public.

Create a new interface


Define the methods


Create an class to implement the methods defined by the interface. If we don't want to implement them, then the class must be abstract. In this case we will define a base class.




If we want to implement  the methods  define by the interface in a struct, we must make directly  of the interface because the struct does not support inheritance.
  




Implementation the derived classes


Create a test method to test the struct

                                 
Run the struct





Create a test method to test the derived class using base class.



Test run








Create a test method to test derived class using the interface.


Test run










No hay comentarios:

Publicar un comentario