Integ - Interface

  • Interfaces are a contract that contains only the signatures of methods, properties, and events as its members.

  • Interfaces are not classes.

  • In C#, interfaces are defined using the interface keyword.

  • An interface only contains the signatures of methods, properties, and events as its members.

  • The class implementing the interface is responsible for providing the implementation of the members.

  • Interfaces cannot be instantiated.

  • Interface members cannot contain any code that implement its members; only the signatures can.

  • A common naming convention is to begin all interface names with a capital I.

  • The modifiers of the members of an interface are all public by default.

  • When a class implements an interface, the class can invoke the interface members directly from the object level.

  • An interface can be implemented on a class using the colon (:) symbol.

  • An interface declares methods without a method body or implementation.

  • The class implementing the interface defines the methods and provides them with the implementation.

  • The method implementation in the class must have the same signature, parameters, and method name as defined in the interface. Otherwise, the compiler will return an error.

  • Interfaces ensure that the implementing classes implement all the methods and properties declared in the interface.

  • A class can inherit only one (1) base class, but a class can implement multiple interfaces.

  • When a class implements multiple interfaces, the implementing class must implement all the members of the interfaces.

  • To implement multiple interfaces, the colon (:) symbol is used, and the interfaces are declared in a comma-separated list.

  • An interface cannot contain instance variables or fields.

  • An interface may contain properties.

  • A property can access a private data member of the class.

  • A read (get) and write (set) property can be declared in an interface using the syntax: datatype propertyName { get; set; }.

  • The accessors (get and set) of an interface does not have a body.

  • The purpose of the accessors is to indicate the properties are read-write.

  • Properties declared in the interface are used to access the private variables declared on the class.