Unit 6: Design patterns
Ten patterns that come up again and again in LLD interviews and real code: three for creating objects, three for structuring them, and four for behaviour.
The big picture
A pattern is a proven shape for a common problem, with a name everyone recognises. In an interview, naming the right pattern — and saying why it fits — shows you design for change, not just for today.
Lessons in this unit
- Singleton: Makes sure a class has only one instance, and gives one global way to reach it.
- Factory: Factory Method and Abstract Factory: A factory creates objects for you, so the calling code asks for 'a notifier' without knowing which concrete class gets built.
- Builder: Builds a complex object step by step, instead of using a constructor with a dozen parameters.
- Adapter: Lets two incompatible interfaces work together, by wrapping one so it looks like the other.
- Decorator: Adds behaviour to an object by wrapping it in another object with the same interface, without changing the original class.
- Facade: Gives one simple interface to a complicated set of classes.
- Strategy: Puts a family of interchangeable algorithms behind one interface, so you can choose one at runtime.
- Observer: Lets objects subscribe to another object's events, and get notified automatically when something happens.
- Chain of Responsibility: Passes a request along a chain of handlers; each one either deals with it or passes it on to the next.
- State: Lets an object change its behaviour when its internal state changes, by putting each state's behaviour in its own class.