- State Pattern
Introduction The State Pattern allows an object to alter its behavior when its internal state changes, making it appear as though the object has changed its class. Instead of scattering state-dependent logic across methods with conditionals, you encapsulate each state into its own class, and the…
- Template Method Pattern
Introduction The Template Method Pattern defines the skeleton of an algorithm in a base class, letting subclasses override specific steps without changing the algorithm’s overall structure. The base class controls the workflow — the “what” and “when” — while subclasses provide the “how” for…
- Observer Pattern
Introduction The Observer Pattern establishes a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. Think of it as a subscription model — interested parties register to receive updates, and the publisher broadcasts…
- Strategy Pattern
Introduction The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable at runtime. Instead of hardcoding behavior into a single class with conditionals, you extract each algorithm into its own class and let the client choose which one to use. This is…
- Decorator Pattern
Introduction The Decorator Pattern is a structural design pattern that lets you attach new behaviors to objects by wrapping them in special objects that contain the added behavior. Think of it like adding toppings to a coffee — you start with a base espresso, then wrap it with milk, then wrap that…