Explore advanced design patterns such as Singleton, Factory, Observer, and Strategy, understanding their implementations and when to apply them in software development.
Design Patterns – Quick Reference Notes
| Aspect | Description |
|---|---|
| Definition | A reusable solution to a common software‑design problem. It describes what to do, not how to code it. |
| Purpose | Improves code readability, promotes best practices, and speeds up development by providing proven templates. |
| Scope | Architectural (e.g., MVC), creational, structural, and behavioral patterns. |
| Category | Goal | Typical Use‑Cases | Common Patterns |
|---|---|---|---|
| Creational | Object creation mechanisms that increase flexibility and reuse. | When object creation is complex, needs to be delayed, or must vary at runtime. | Singleton, Factory Method, Abstract Factory, Builder, Prototype |
| Structural | Organizing classes and objects to form larger structures while keeping them flexible. | When you need to compose objects, hide implementation details, or adapt interfaces. | Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy |
| Behavioral | Managing algorithms, communication, and responsibilities among objects. | When you need clear interaction protocols, state‑dependent behavior, or decoupled communication. | Observer, Strategy, Command, Iterator, Mediator, Memento, State, Template Method, Visitor, Chain of Responsibility |
Ensures a class has only one instance and provides a global access point.
Defines an interface for creating an object, but lets subclasses decide which class to instantiate.
Creator class with abstract factoryMethod(), concrete ConcreteCreator overrides it.Provides an interface for creating families of related objects without specifying concrete classes.
AbstractFactory with methods for each product, concrete factories implement them.Separates construction of a complex object from its representation.
Builder interface, concrete builders, Director orchestrates building, fluent API for chaining.Creates new objects by copying an existing instance (prototype).
clone() (shallow vs. deep copy), prototype registry.Converts one interface into another that a client expects.
Decouples an abstraction from its implementation so the two can vary independently.
Abstraction holds a reference to Implementor.