Conceptly
← All Concepts
πŸ”Œ

Interface

StructureA contract that promises behavior without implementation

An interface is a contract that declares which operations must exist while leaving the implementation of those operations to concrete types. Callers can depend on the contract rather than on one class name and its internals.

β–ΆArchitecture Diagram

πŸ”— Relationship

Dashed line animations indicate the flow direction of data or requests

Why do you need it?

When calling code is tightly coupled to a specific class, changing storage strategy, integration details, or test setup often forces the upper layer to change too. That coupling also makes it harder to substitute test doubles or alternate implementations.

Why did this approach emerge?

Large object-oriented systems repeatedly needed to support several implementations of the same role: in-memory storage versus file storage, production service versus test double, and so on. Interface-driven design spread because it offered a stable role boundary across those differences.

How does it work inside?

An interface usually defines only method names and input/output shapes. Multiple classes can implement that contract, and callers need to know only that the contract is satisfied, not which concrete class is underneath.

Boundaries & Distinctions

Interfaces and abstract classes both create common surfaces, but interfaces focus on the contract itself while abstract classes also carry shared implementation. If you want a lightweight role boundary without shared code, an interface is the simpler tool.

When should you use it?

Interfaces fit roles such as notifier, storage adapter, or payment gateway where the responsibility stays the same but implementations may change. If there is only one concrete implementation and little realistic chance of substitution, introducing an interface too early can add ceremony without real flexibility.

Swap implementations -- change concrete behavior while keeping the same contractUse test doubles -- let callers depend on a role instead of one concrete classEnable plugin structures -- let external modules participate by implementing a fixed surfaceSplit team responsibilities -- coordinate work around interface-level promises