Design Patterns and OOP Design (LLD) Tutorial
Learn Design Patterns and OOP Design (LLD) step by step: 57 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started with Design
- What Are Design Patterns? Learn what design patterns are, where they come from, how they differ from algorithms and frameworks, when they hurt, and how to read a pattern description.
- Reading and Drawing UML for Low-Level Design Read and draw UML class diagrams and sequence diagrams for low-level design: relationships, multiplicity, visibility and Mermaid syntax, with runnable examples.
- OOP Foundations for Design Review encapsulation, abstraction, inheritance and polymorphism with a design focus. Compare interfaces and abstract classes across Java, C++, Python and JavaScript.
Design Principles
- SOLID at a Glance A tour of the five SOLID principles: why they exist, how they relate to design patterns, their trade-offs, and a runnable example of code that breaks several at once.
- Single Responsibility Principle Learn the Single Responsibility Principle: reasons to change, cohesion, how to split a god class, and a before and after report printer example you can run.
- Open/Closed Principle Learn the Open/Closed Principle: extend behavior without editing tested code. Replace if-else chains with polymorphism and strategy in a runnable discount example.
- Liskov Substitution Principle Learn the Liskov Substitution Principle: behavioral subtyping, the square and rectangle trap, contracts, and a contract test that catches violations.
- Interface Segregation Principle Learn the Interface Segregation Principle: why fat interfaces hurt, how role interfaces fix them, with a printer and scanner example and mixins.
- Dependency Inversion and Dependency Injection Understand the Dependency Inversion Principle, constructor injection and inversion of control, and build a tiny dependency injection container.
- Inversion of Control and IoC Containers Learn what Inversion of Control means, how it differs from Dependency Injection, the Service Locator and DIP, and build a small IoC container with lifetimes and cycle detection.
- DRY, KISS, YAGNI, Law of Demeter and Composition over Inheritance Learn the everyday design rules beyond SOLID: DRY, KISS, YAGNI, the Law of Demeter, tell don't ask, cohesion, coupling and composition over inheritance.
Creational Patterns
- Singleton Learn the Singleton design pattern: lazy and eager creation, thread safety in Java and C++, module singletons, and why it often hurts testing.
- Factory Method Learn the Factory Method design pattern: creator and product hierarchies, parameterized factories, static factory methods and when to use each.
- Abstract Factory Learn the Abstract Factory design pattern: build families of related objects, such as a UI theme kit, and swap the whole family at runtime.
- Builder Learn the Builder design pattern: avoid telescoping constructors, write fluent builders, use a director, and validate in build() to get immutable objects.
- Prototype Learn the Prototype design pattern: create objects by cloning, understand shallow vs deep copies, use a prototype registry and structuredClone.
- Object Pool, Lazy Initialization and Dependency-Free Creation Learn the Object Pool and Lazy Initialization patterns: reuse expensive objects, write a connection pool, build a lazy proxy and know when not to pool.
Structural Patterns
- Adapter Learn the Adapter design pattern: wrap an incompatible interface so it fits yours, with legacy API and payment gateway examples and the object vs class forms.
- Bridge Learn the Bridge design pattern: split an abstraction from its implementation so shapes and renderers vary independently and classes do not multiply.
- Composite Learn the Composite design pattern: treat single objects and groups the same way through one interface, with a file system tree and recursion examples.
- Decorator Learn the Decorator design pattern: wrap an object to add behavior at run time, stack decorators, and compare the pattern with Python and JavaScript decorators.
- Facade Learn the Facade design pattern: hide a complicated subsystem behind one simple interface, with home-theater and checkout examples, and compare it with Adapter.
- Flyweight Learn the Flyweight design pattern: split intrinsic from extrinsic state and share objects to save memory, with a text editor glyph example and size estimates.
- Proxy Learn the Proxy design pattern: virtual, protection, caching and logging proxies, the JavaScript Proxy object, and how a remote proxy hides the network.
Behavioral Patterns
- Strategy Learn the Strategy design pattern: make algorithms interchangeable, replace long if-else chains, and use plain functions as strategies in sorting and pricing.
- Observer Learn the Observer design pattern: one subject notifies many observers when it changes. Covers push vs pull, EventEmitter, and memory leaks from forgotten unsubscribes.
- Command Learn the Command design pattern: turn a request into an object so you can undo it, redo it, queue it, log it and combine commands into macros.
- State Learn the State design pattern: let an object change its behavior when its state changes. Compare state objects with enums using a vending machine and order workflow.
- Template Method Learn the Template Method design pattern: define the skeleton of an algorithm in a base class, let subclasses fill in steps and hooks, and compare it with Strategy.
- Iterator Learn the Iterator design pattern: visit the items of a collection one at a time without exposing its structure. Includes JS generators, Python __iter__ and Java Iterable.
- Chain of Responsibility Learn the Chain of Responsibility design pattern: pass a request along a chain of handlers. Covers approval workflows, middleware pipelines and logging levels.
- Mediator and Memento Learn the Mediator pattern to centralize communication between objects and the Memento pattern to save and restore state for undo, with runnable examples.
- Visitor, Interpreter and Null Object Learn Visitor and double dispatch to add operations to a class hierarchy, Interpreter for small languages, and Null Object to remove null checks.
- Interpreter Pattern in Depth Learn the Interpreter design pattern step by step: define a grammar, build terminal and non-terminal expression classes, parse text into a tree and evaluate it.
- Null Object Pattern Learn the Null Object pattern: replace null with a do-nothing object that shares the interface, remove scattered null checks, and know when this hides real errors.
Architectural and Modern Patterns
- Repository and Unit of Work Separate persistence from domain logic with the Repository pattern, test with in-memory repositories, and group changes into one transaction with Unit of Work.
- MVC, MVP and MVVM Compare MVC, MVP and MVVM presentation patterns: what each part does, how data flows, and where each fits, with a runnable tiny MVC app and a view-model.
- Dependency Injection, Service Locator and Plugin Architectures Wire objects with a composition root, see why the Service Locator hides dependencies, build a plugin registry, and test with fakes and spies.
- Patterns Across Languages: Java, C++, Python and JavaScript See how design patterns change across Java, C++, Python and JavaScript: which ones vanish with closures, duck typing and modules, and what RAII replaces.
- CQRS: Command Query Responsibility Segregation Learn CQRS: split the write model from the read model, keep them in sync with events, and know the costs. Includes a runnable order example with a projection.
- Event Sourcing Learn Event Sourcing: store every change as an event, rebuild state by replay, speed it up with snapshots, and know when this pattern is worth its cost.
- Event-Driven Architecture Learn event-driven architecture: producers, consumers and brokers, pub/sub versus queues, event notification versus state transfer, and the limits to plan for.
- Circuit Breaker, Retry and Bulkhead Patterns Learn resilience patterns for calling unreliable services: retry with backoff, circuit breaker states, fallbacks and bulkheads, with runnable stand-ins you can step through.
Anti-Patterns and Refactoring
- Anti-Patterns and Code Smells Learn the most common design anti-patterns and code smells: god object, spaghetti code, singleton abuse, anemic model, golden hammer and primitive obsession, with fixes.
- Refactoring to Patterns Learn how to refactor messy conditional code to Strategy, State and Factory step by step, with characterization tests that stay green after every small change.
Low-Level Design Projects
- How to Approach a Low-Level Design Problem A repeatable framework for low-level design: clarify requirements, find entities, model relationships, define APIs, apply patterns, handle concurrency and plan extensions.
- Project: Parking Lot Design a parking lot system step by step: vehicles, spots, tickets, a pricing strategy, a vehicle factory and concurrency, with a complete runnable Node.js model.
- Project: Elevator System Design an elevator system with the State pattern for each car, a scheduling strategy for dispatching, a request queue and an observer for floor displays, in runnable Node.js.
- Project: Library Management System Design a library system: members, books, copies, loans, reservations, fine strategies, an observer for notifications and a repository layer, with runnable Node.js code.
- Project: Ride Sharing and Vending Machine Two classic low-level design projects: a ride-sharing dispatcher with matching and pricing strategies, and a vending machine built with State and Command.
- Project: Text Editor with Undo and a Chess Engine Core Build a text editor with undo and redo using Command and Memento, then model a chess core with Strategy for piece movement and Composite for armies.
- Project: In-Memory File System Design an in-memory file system step by step: files and directories as a Composite tree, path resolution, mkdir, read, write, ls, mv and rm, with runnable Node.js code.
Practice and Interview Prep
- Design Pattern Exercises with Solutions Practice 15 design pattern exercises across creational, structural and behavioral patterns, each with a short runnable JavaScript solution and review hints.
- Low-Level Design Exercises with Solutions Six classic low-level design exercises with runnable Node.js solutions: ATM, notification service, rate limiter, logger framework, LRU cache and tic-tac-toe.
- Design Pattern and OOP Interview Questions More than 40 design pattern, OOP and SOLID interview questions with concise answers, comparisons such as strategy vs state, and two runnable code demos.
- Design Patterns Cheat Sheet A one-page design patterns cheat sheet: intent, when to use, structure, pitfalls and language idioms for every GoF pattern plus SOLID and a pattern picker.
- Design Patterns Hidden in the JDK and Popular Frameworks Spot Singleton, Factory, Builder, Decorator, Observer, Iterator, Strategy and more inside the Java standard library and Spring, with runnable examples.