What Do Design Patterns Really Mean? A Playful Guide to 23 Patterns
The article humorously explains 23 classic software design patterns—ranging from creational to behavioral—using everyday dating scenarios to illustrate each pattern's intent, structure, and typical usage, making the concepts easy to grasp for developers.
Factory Method
The Factory Method defines an interface for creating an object, but lets subclasses decide which class to instantiate. It decouples client code from concrete product classes.
Creator : declares the factory method.
ConcreteCreator : overrides the factory method to return an instance of a ConcreteProduct .
Product : defines the interface of objects the factory method creates.
ConcreteProduct : implements the Product interface.
Typical use: when a class cannot anticipate the class of objects it must create, or when a class wants its subclasses to specify the objects to create.
Pros : promotes loose coupling, adheres to Open/Closed Principle. Cons : introduces additional subclassing.
Builder
The Builder pattern separates the construction of a complex object from its representation, allowing the same construction process to create different representations.
Builder : specifies abstract construction steps.
ConcreteBuilder : implements the steps and assembles the product.
Director : orchestrates the building process using a Builder .
Product : the complex object under construction.
Use when an object requires many optional parameters or when the construction process must be independent of the parts that make up the object.
Abstract Factory
Abstract Factory provides an interface for creating families of related or dependent objects without specifying their concrete classes.
AbstractFactory : declares creation methods for each kind of product.
ConcreteFactory : implements the creation methods for a specific product family.
AbstractProduct : declares an interface for a type of product.
ConcreteProduct : implements the AbstractProduct interface.
Useful when a system must be independent of how its products are created and when products from the same family must be used together.
Prototype
Prototype creates new objects by copying an existing object, known as the prototype. It is useful when object creation is expensive or complex.
Prototype : declares a cloning method.
ConcretePrototype : implements the cloning operation.
Clients request a clone of a prototype instead of constructing a new instance from scratch.
Singleton
Singleton ensures a class has only one instance and provides a global point of access to it.
Private constructor to prevent external instantiation.
Static method (e.g., getInstance()) returns the sole instance.
Appropriate when exactly one object is needed to coordinate actions across the system (e.g., configuration manager, logger).
Adapter
Adapter converts the interface of a class into another interface clients expect, allowing incompatible classes to work together.
Target : defines the domain-specific interface used by the client.
Adaptee : existing interface that needs adapting.
Adapter : implements Target and holds an instance of Adaptee , translating calls.
Bridge
Bridge decouples an abstraction from its implementation so that the two can vary independently.
Abstraction : defines high-level control logic.
RefinedAbstraction : extends the abstraction.
Implementor : defines low-level operations.
ConcreteImplementor : provides concrete implementation of those operations.
Composite
Composite composes objects into tree structures to represent part‑whole hierarchies. Clients treat individual objects and compositions uniformly.
Component : declares interface for all objects in the composition.
Leaf : represents end objects with no children.
Composite : stores child components and implements component interface by delegating to children.
Decorator
Decorator adds responsibilities to objects dynamically without affecting other objects of the same class.
Component : defines the interface for objects that can have responsibilities added.
ConcreteComponent : the original object.
Decorator : maintains a reference to a Component and implements the same interface.
ConcreteDecorator : adds behavior before/after delegating to the wrapped component.
Facade
Facade provides a unified high‑level interface to a set of interfaces in a subsystem, making the subsystem easier to use.
Facade : defines a simple interface that delegates calls to subsystem classes.
Clients interact with the facade instead of directly with complex subsystem components.
Flyweight
Flyweight reduces memory consumption by sharing common intrinsic state among many fine‑grained objects while keeping extrinsic state external.
Flyweight : defines methods that accept extrinsic state.
ConcreteFlyweight : implements the shared intrinsic state.
FlyweightFactory : creates and manages flyweight objects, ensuring reuse.
Proxy
Proxy provides a surrogate or placeholder for another object to control access, add responsibilities, or defer expensive operations.
Subject : defines the common interface.
RealSubject : the actual object.
Proxy : controls access to RealSubject , possibly adding caching, lazy initialization, or access control.
Chain of Responsibility
Chain of Responsibility passes a request along a chain of handlers until one handles it, decoupling sender and receiver.
Handler : defines an interface for handling requests and optionally forwarding them.
ConcreteHandler : processes the request or forwards it.
Command
Command encapsulates a request as an object, thereby allowing parameterization of clients with queues, logs, or undo operations.
Command : declares an interface for executing an operation.
ConcreteCommand : binds a receiver and an action.
Invoker : stores and triggers commands.
Receiver : performs the actual work.
Interpreter
Interpreter defines a grammatical representation for a language and provides an interpreter to evaluate sentences in the language.
AbstractExpression : declares an interpret method.
TerminalExpression : implements interpretation for terminal symbols.
NonterminalExpression : implements interpretation for non‑terminal symbols, typically delegating to other expressions.
Iterator
Iterator provides a way to access elements of an aggregate object sequentially without exposing its underlying representation.
Iterator : defines next(), hasNext(), and optionally remove().
ConcreteIterator : implements traversal for a specific aggregate.
Aggregate : defines a method createIterator().
Mediator
Mediator centralizes complex communications and control logic between related objects, reducing direct dependencies.
Mediator : defines an interface for communication.
ConcreteMediator : coordinates interactions among Colleague objects.
Colleague : knows its mediator and communicates through it.
Memento
Memento captures and externalizes an object's internal state without violating encapsulation, allowing the state to be restored later.
Originator : creates a memento containing a snapshot of its current state and can restore its state from a memento.
Memento : stores the snapshot.
Caretaker : holds and protects mementos but never examines their contents.
Observer
Observer defines a one‑to‑many dependency so that when the subject changes, all its observers are automatically notified.
Subject : maintains a list of observers and provides methods to attach/detach them.
Observer : defines an update interface for receiving notifications.
State
State allows an object to alter its behavior when its internal state changes, appearing as if the object changed its class.
Context : maintains a reference to a State object.
State : defines an interface for encapsulating behavior associated with a particular state.
ConcreteState : implements behavior for a specific state and may transition the context to another state.
Strategy
Strategy defines a family of algorithms, encapsulates each one, and makes them interchangeable. The client selects a concrete strategy at runtime.
Strategy : declares an interface common to all supported algorithms.
ConcreteStrategy : implements a specific algorithm.
Context : is configured with a Strategy object and delegates execution to it.
Template Method
Template Method defines the skeleton of an algorithm in an abstract class, deferring some steps to subclasses.
AbstractClass : implements the template method and defines abstract primitive operations.
ConcreteClass : overrides the primitive operations to provide specific behavior.
Visitor
Visitor separates an algorithm from the object structure on which it operates, allowing new operations to be added without modifying the elements.
Visitor : declares a visit method for each concrete element type.
ConcreteVisitor : implements the operations to be performed on elements.
Element : defines an accept(Visitor) method.
ConcreteElement : implements accept by calling the appropriate visitor method.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
