An interface defines a contract that specifies a "can do" relationship or a "has a" relationship. Interfaces are often used to implement functionality, such as comparing and sorting (the IComparable and IComparable<(Of <(T>)>) interfaces), testing for equality (the IEquatable<(Of <(T>)>) interface), or enumerating items in a collection (the IEnumerable and IEnumerable<(Of <(T>)>) interfaces). Interfaces can have properties, methods, and events, all of which are abstract members; that is, although the interface defines the members and their signatures, it leaves it to the type that implements the interface to define the functionality of each interface member. This means that any class or structure that implements an interface must supply definitions for the abstract members declared in the interface. An interface can require that any implementing class or structure must also implement one or more other interfaces.
The following restrictions apply to interfaces:
-
An interface can be declared with any accessibility, but interface members must all have public accessibility.
-
Interfaces cannot define constructors.
-
Interfaces cannot define fields.
-
Interfaces can define only instance members. They cannot define static members.
Each language must provide rules for mapping an implementation to the interface that requires the member, because more than one interface can declare a member with the same signature, and these members can have separate implementations.