An interface refers to the designated point of interaction with a component. Interfaces are applicable at both the hardware and software level. --- It also refers to the language-element `interface`, which is the sole exception to single-inheritance in Java, C# and similar languages.
An interface is the designated point of interaction with a component.
Well-defined, comprehensive, versatile but still minimal interfaces are critical for reliability, extensibility, maintainance, and compatibility.
In programming, we mostly encounter:
- apis, which consist of symbols (types (and all they might entail), functions, constants, variables, templates, namespaces and so on), and their defined behavior, which might include their own turing-complete languages.
- abis, which define the mapping of APIs to the underlying machine.
- protocols, which define interactions over a connection, network, or the like.
- And many combined ones, especially in directly interacing with a device, for example to write a device-driver.
In some languages, mostly object-oriented single-inheritance ones, an interface
is a restricted type not containing any state nor instantiable by itself, and only able to inherit from (any number of) other interface
s.
A class can implement any number of interface
s in addition to inheriting from a single other class
(most of those languages enforce a single-root inheritance-hierarchy).
Most insist that the base-class is listed first, and some allow explicitly implementing an interface
s members, which makes them inaccessible except through an interface
-pointer of that type.
The implementation of an interface
varies between programming languages and environments; for e.g. C# has the following definition (Interfaces (C# Programming Guide));
Interfaces describe a group of related functionalities that can belong to any class or struct. You define an interface by using the interface keyword, as shown in the following example.
interface IEquatable<T> {
bool Equals(T obj);
}
An interface may or may not contain or make use of any number of interface
s or their equivalent.
You can "program to the interface, not the implementation" without using any interface
, as well as fail to but still use interface
s all over the place.
The [interface]-tag should should be used in conjunction with the appropriate [language]-tag(s) where applicable.