Interface
ELI5 — The Vibe Check
An interface is like a job description. It says 'whatever fills this role must be able to do X, Y, and Z' without caring how they do it. A human or a robot can both fill the role as long as they meet the requirements.
Real Talk
An interface defines a contract — a set of method signatures and property shapes that a class or object must implement. It enables polymorphism and decoupled code by programming to abstractions rather than concrete implementations.
Show Me The Code
// TypeScript interface
interface Animal {
name: string;
speak(): string;
}
class Dog implements Animal {
name = "Rex";
speak() { return "Woof!"; }
}
When You'll Hear This
"Define an interface for the payment provider so we can swap Stripe for PayPal later." / "That class doesn't implement the interface correctly."
Related Terms
Class
A class is a blueprint for creating objects.
Generic
A generic is like a recipe that works for any ingredient.
OOP (OOP)
OOP is a way of organising code by modelling the world as objects — things that have properties (what they are) and methods (what they do).
Type Inference
Type inference is the compiler being smart enough to figure out what type something is without you having to spell it out.