Class
ELI5 — The Vibe Check
A class is a blueprint for creating objects. If you want to make lots of cars, you write a Car blueprint once — specifying it has 4 wheels, a color, and can drive. Then you can stamp out as many Car objects as you want from that blueprint.
Real Talk
A class is a user-defined type that bundles data (properties) and behaviour (methods) together. You instantiate a class with new to create an object. Classes support inheritance, encapsulation, and polymorphism.
Show Me The Code
class User {
constructor(public name: string, public email: string) {}
greet(): string {
return `Hi, I'm ${this.name}`;
}
}
const user = new User("Alice", "alice@example.com");
user.greet(); // "Hi, I'm Alice"
When You'll Hear This
"Create a User class with name and email properties." / "That class has too many responsibilities — time to refactor."
Related Terms
Boilerplate
Code you have to write every single time you start a project but that doesn't actually do anything interesting.
Generic
A generic is like a recipe that works for any ingredient.
Interface
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.
Method
A method is just a function that belongs to an object or class. Your Dog object has a bark() method — it's the dog's personal function.
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).