Computer ScienceProgrammingMedium

Interface (OOP)

Also known as:protocol (Swift)trait (Rust/Scala)abstract type

An interface in OOP is a fully abstract type that defines a set of method signatures (a contract) that any implementing class must fulfil, without specifying how those methods work. Interfaces enable multiple inheritance of type in languages like Java and C#, allowing a class to implement several interfaces simultaneously. They promote loose coupling in software design by allowing different classes to be used interchangeably when they implement the same interface.

Interfaces in Common OOP Languages

LanguageKeywordMultiple Implementation?Default Methods?
JavainterfaceYesYes (Java 8+)
C#interfaceYesYes (.NET 8+)
TypeScriptinterfaceYesNo
PythonABC / ProtocolYesN/A
GointerfaceYes (implicit)No

Interactive Tools

W3Schools – Java Interfaces

Open Tool

Codecademy – Interfaces and Polymorphism

Open Tool

Brilliant – Interfaces

Open Tool
UML diagram showing a class implementing an interface contract

Wikimedia Commons, CC BY-SA

Related Terms

Computer Science

Abstraction (OOP)

Abstraction in OOP is the principle of exposing only the essential features of an object to the outside world while hiding the complex implementation details. It is achieved through abstract classes and interfaces, which define a contract specifying what methods a class must implement without dictating how they are implemented. Abstraction reduces complexity for the programmer using the class and allows internal implementations to change without affecting dependent code.

Computer Science

Polymorphism

Polymorphism is the OOP principle that allows a single interface or method name to represent different underlying implementations depending on the object type. There are two main forms: compile-time polymorphism (method overloading, where multiple methods share a name but differ in parameters) and runtime polymorphism (method overriding, where a subclass provides its own implementation of a parent's method). Polymorphism makes programs more flexible and extensible, allowing new object types to be added without changing existing code.

Computer Science

Inheritance (OOP)

Inheritance is an OOP mechanism whereby a child class (subclass) automatically acquires the attributes and methods of a parent class (superclass), enabling hierarchical relationships between classes. The subclass can extend or override inherited behaviour without modifying the original parent class, promoting code reuse and reducing duplication. Inheritance models real-world "is-a" relationships, such as a Dog being an Animal.

From Latin "inter" (between) and "facies" (face/surface), meaning the surface between two things. In computing, the term was used in hardware design before migrating to software, where it describes the boundary or contract between components. Java (1995) popularised the interface keyword in OOP.

interfaceoopcontractabstractionmultiple-inheritance