In computer science, an interface is a specification that exists between software components that specifies a selected means of interaction, by means of properties of other software modules, which abstract and encapsulate their data.
An interface defines the means of interaction between software components - this includes constants, data types, procedures, and method signatures. In some instances, it may be useful to define variables as part of the interface. It often also specifies the functionality of those procedures and methods, either by comments or (in some experimental languages) by formal logical assertions.
The interface of a software module is deliberately kept seperate from the implementation of that module. The latter contains the actual code of the procedures and methods described in the interface, as well as other "private" variables, procedures, etc.. Any other software module (which can be referred to as a client to A) that interacts with is forced to do so only through the interface. One practical advantage of this arrangment is that replacing the implementation of by another one that meets the same specifications of the interface should not cause to fail — as long its use of complies with the specifications of the interface.
The concept of interface is the cornerstone of modular programming, a forerunner and a standard ingredient of object-oriented programming. In object-oriented programming, an object's interface consists of a set of methods that the object will typically respond to. Note that the object does not make its instance variables a part of its interface - these are typically accessed by means of accessor methods. Some object-oriented programming languages mandate that the interface to the object be specified to the compiler seperately from the implementation of that object, whilst others relax the requirement.
Interfaces were historically derived from the header files of the C programming language by restricting their syntactic context and contents, and making them a part of the language semantics (as opposed to a mere preprocessor feature).
Certain programming languages have different methodologies for allowing the construction of interfaces. In general, any programming language can implement an interface, but the following programming languages provide specific interface constructs in the programming language of some kind:
- Mesa (Xerox PARC, ca. 1978)
- Modula (Niklaus Wirth, ETH Zurich, 1980s)
- Modula-2 (Xerox PARC, ca. 1983)
- Oberon (Niklaus Wirth, ETH Zurich, 1980s)
- Modula-3 (DEC SRC, 1980s)
- Java
- C# (included in Microsoft DotNet).
- Objective-C