Software → Software Design
Interface
A boundary or contract that defines how one part of a program can interact with another.
Motivation
An interface solves the problem of depending on behavior without depending on a specific implementation. It lets code communicate through a contract.
Where it fits
Interfaces are central to programming, OOP, dependency inversion, dependency injection, testing, and modular architecture.
Mental model
An interface says “anything that can do these operations can be used here.” That allows replacement, testing, and independent evolution.
Example
interface EmailSender {
send(to: string, body: string): Promise<void>;
}
The caller does not need to know whether the implementation uses SMTP, an API, or a fake test double.
Common mistakes
- Creating interfaces with only one implementation and no reason.
- Making interfaces too large.
- Confusing interface with user interface.