Search
Lessons (40)
- Classes and Objects
… Learn constructors, properties, methods, this, and static members with simple examples. The big idea A cookie cutter is …
- Polymorphism
… number; } class Circle implements Shape { constructor(private radius: number) {} area() { return Math.PI this.radius 2; } } class Rectangle …
- Inheritance
… string) { super(name); // call the parent constructor FIRST } speak() { // override return ${this.name} barks. ; } fetch() { // new method only …
- Object Relationships: Association, Aggregation and Composition
… Patient) { this.patients.push(p); } } class Patient { constructor(public name: string) {} } const ana = new Patient("Ana"); const drLee …
- D — Dependency Inversion Principle
… invert the dependency js // ✅ OrderService depends only on "shapes" it receives class OrderService { constructor({ orderRepository, mailer }) { this.orderRepository …
- Clean Error Handling
… Custom error classes let them react precisely. js class AppError extends Error { constructor(message, statusCode) { super(message); this …
- NestJS Core Concepts
… AuthedRequest) { return this.orders.create(req.user.id, dto); } } @Injectable() export class OrdersService { constructor(@InjectRepository(Order) private readonly …
- Composition over Inheritance
… string) { return ${name} doesn't fight ; } } class Character { constructor( public name: string, private movement: Movement, // has-a private …
- Interfaces vs Abstract Classes
… It can contain: - real methods that all children share, - fields and a constructor , - abstract methods with no body …
- Structural Patterns: How to Connect Objects
… winston.write({ severity, text, ts }) class WinstonAdapter { constructor(winston) { this.winston = winston; } log(level, message) { this.winston.write …
- Domain-Driven Design: Tactical Patterns
… Money) { return this.cents === other.cents && this.currency === other.currency; } } export class Email { private constructor(readonly value: string …
- Code Smells & Refactoring
… return shape.side 2; } } // ✅ Each shape knows how to compute its own area class Circle { constructor(r) { this …
- Clean Architecture
… pure business rules js // domain/User.js — no imports from frameworks or databases export class User { constructor({ id …
- OOP Mistakes and Interview Questions
… What is a constructor? Can it be private?</strong </summary A constructor is the special method that runs …
- Hexagonal Architecture (Ports & Adapters)
… domain + ports + use case ts // core/domain/Loan.ts export class Loan { constructor(readonly bookId: string, readonly memberId …
- Layered (N-Tier) Architecture
… return 201 JSON ts // presentation/OrderController.ts export class OrderController { constructor(private orders: OrderService) {} async create(req: Request …
- Clean Architecture in Depth
… number }; export class Order { private constructor( readonly id: string, readonly customerId: string, private lines: OrderLine[], private status: "PENDING …
- Creational Patterns: How to Make Objects
… Same process, many different results. Problem: an object has many optional parts , and a constructor with 10 parameters …
- I — Interface Segregation Principle
… Promise<void ; } class ReportService { constructor(private orders: OrderReader) {} } // can't delete by accident class CheckoutService { constructor(private orders …
- L — Liskov Substitution Principle
… don't force the inheritance js // ✅ Both are shapes; neither pretends to be the other class Rectangle { constructor …
- JavaScript Language Fundamentals
… js class Animal { energy = 10; // truly private field constructor(name) { this.name = name; } eat() { this. energy++; return this …
- Behavioral Patterns II: Chain, Template, Iterator, Mediator, Memento, Visitor
… anything with [Symbol.iterator] works with for…of , spread and destructuring. js class Playlist { constructor(songs) { this.songs …
- SOLID at a Glance
… add new exporters class ExcelExporter { export(report) {} } // without editing old ones class ReportService { constructor(repository, notifier) { // D: injected …
- O — Open/Closed Principle
… new rules never touch this class class PriceCalculator { constructor(private rules: DiscountRule[]) {} total(cart: Cart): number { const best …
- S — Single Responsibility Principle
… split by actor js // ✅ One reason to change each class Employee { constructor(id, name, hourlyRate) { Object.assign(this …
- YAGNI: You Aren't Gonna Need It
… nobody asked for PDF, XML, plugins or custom delimiters class ExportEngine { constructor({ format = "csv", delimiter = ",", encoding = "utf-8 …
- Which Pattern Do I Need?
… br/ or depends on conditions"] -- F[Factory] P2["Constructor has too<br/ many parameters"] -- B[Builder] P3["Need …
- Hash Maps & Sets
… Plain objects have inherited keys like "constructor" that can surprise you. Pattern 1: "Have I seen it before …
- Abstraction
… depends only on the abstraction : ts class Checkout { constructor(private payments: PaymentGateway) {} async pay(orderTotal: number, cardToken: string …
- Linked Lists
… img/dsa/linked-list.svg) js class ListNode { constructor(value, next = null) { this.value = value; this.next = next …
- What Is Object-Oriented Programming?
… only code inside the class can touch it constructor(public readonly owner: string) {} deposit(amount: number) { if (amount …
- Encapsulation
… string; // everyone constructor(id: string, name: string, passwordHash: string) { this.id = id; this.name = name; this.passwordHash = passwordHash …
- Go Fundamentals
… An Account struct with an unexported balance field and a NewAccount(owner string) constructor. 2. Deposit and Withdraw …
- Trees & Binary Search Trees
… 2 children (left and right) js class TreeNode { constructor(value, left = null, right = null) { this.value = value; this …
- Heaps & Priority Queues
… heart for interviews: js class MinHeap { items = []; compare; constructor(compare = (a, b) = a - b) { this. compare = compare; } get …
- Backend Languages: Node.js, Go, Python & Rust
… It's great for larger teams. ts @Controller("users") export class UsersController { constructor(private readonly users: UsersService) {} // injected …
- MVC, MVP & MVVM
… void; } class LoginPresenter { constructor(private view: LoginView, private auth: AuthService) {} async onLoginClicked(email: string, password: string) { if (!email …
- Node.js and Express
… Click the suspicious constructor (here Session ) and read the Retainers panel. It shows the chain from a GC …
- TypeScript in Practice
… number } class Pixel { constructor(public x: number, public y: number, public color: string) {} } const p: Point = new Pixel …
- Python Fundamentals
… For a normal class, self is the instance, init is the constructor, and "dunder" methods ( len , str , iter …