Skip to main content

Java Design Patterns: Overview

Design patterns are reusable solutions to common software design problems. They provide proven approaches that improve code maintainability, readability, and scalability, while establishing a shared vocabulary for developers to communicate design decisions.

Design Patterns Quick Reference

PatternCategoryComplexityPopularity
Abstract FactoryCreationalβ­β­β˜† (2/3)⭐⭐⭐ (3/3)
AdapterStructuralβ­β˜†β˜† (1/3)⭐⭐⭐ (3/3)
BridgeStructural⭐⭐⭐ (3/3)β­β˜†β˜† (1/3)
BuilderCreationalβ­β­β˜† (2/3)⭐⭐⭐ (3/3)
Chain of ResponsibilityBehavioralβ­β­β˜† (2/3)β­β­β˜† (2/3)
CommandBehavioralβ­β˜†β˜† (1/3)⭐⭐⭐ (3/3)
CompositeStructuralβ­β­β˜† (2/3)β­β­β˜† (2/3)
DecoratorStructuralβ­β­β˜† (2/3)β­β­β˜† (2/3)
FacadeStructuralβ­β˜†β˜† (1/3)β­β­β˜† (2/3)
Factory MethodCreationalβ­β˜†β˜† (1/3)⭐⭐⭐ (3/3)
FlyweightStructural⭐⭐⭐ (3/3)β­β˜†β˜† (1/3)
InterpreterBehavioral⭐⭐⭐ (3/3)β­β˜†β˜† (1/3)
IteratorBehavioralβ­β­β˜† (2/3)⭐⭐⭐ (3/3)
MediatorBehavioralβ­β­β˜† (2/3)β­β­β˜† (2/3)
MementoBehavioral⭐⭐⭐ (3/3)β­β˜†β˜† (1/3)
ObserverBehavioralβ­β­β˜† (2/3)⭐⭐⭐ (3/3)
PrototypeCreationalβ­β˜†β˜† (1/3)β­β­β˜† (2/3)
ProxyStructuralβ­β­β˜† (2/3)β­β˜†β˜† (1/3)
SingletonCreationalβ­β˜†β˜† (1/3)β­β­β˜† (2/3)
StateBehavioralβ­β˜†β˜† (1/3)β­β­β˜† (2/3)
StrategyBehavioralβ­β˜†β˜† (1/3)⭐⭐⭐ (3/3)
Template MethodBehavioralβ­β˜†β˜† (1/3)β­β­β˜† (2/3)
VisitorBehavioral⭐⭐⭐ (3/3)β­β˜†β˜† (1/3)

The Three Categories

CategoryPurposePatterns Covered
CreationalControl how objects are createdSingleton, Factory Method, Abstract Factory, Builder, Prototype
StructuralManage object composition & relationshipsAdapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy
BehavioralDefine how objects communicate & share responsibilityChain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor

Creational Patterns at a Glance

PatternComplexityPopularityIntentKey Mechanism
Abstract Factoryβ­β­β˜† (2/3)⭐⭐⭐ (3/3)Provide an interface for creating families of related objects without specifying their concrete classes.Factory of factories
Builderβ­β­β˜† (2/3)⭐⭐⭐ (3/3)Separate the construction of a complex object from its representation, allowing the same construction process to create different representations.Fluent builder with build()
Factory Methodβ­β˜†β˜† (1/3)⭐⭐⭐ (3/3)Define an interface for creating objects, but let subclasses decide which class to instantiate.Factory method returns interface type
Prototypeβ­β˜†β˜† (1/3)β­β­β˜† (2/3)Create new objects by cloning an existing instance (prototype) rather than constructing from scratch.clone() method
Singletonβ­β˜†β˜† (1/3)β­β­β˜† (2/3)Ensure a class has only one instance and provide a global point of access to it.Private constructor + static accessor

Structural Patterns at a Glance

PatternComplexityPopularityIntentKey Mechanism
Adapterβ­β˜†β˜† (1/3)⭐⭐⭐ (3/3)Convert the interface of a class into another interface clients expect, allowing incompatible interfaces to work together.Wraps adaptee, implements target
Bridge⭐⭐⭐ (3/3)β­β˜†β˜† (1/3)Decouple an abstraction from its implementation so that the two can vary independently.Composition linking two hierarchies
Compositeβ­β­β˜† (2/3)β­β­β˜† (2/3)Compose objects into tree structures to represent part-whole hierarchies, and treat individual objects and compositions uniformly.Component interface for leaf + composite
Decoratorβ­β­β˜† (2/3)β­β­β˜† (2/3)Attach additional responsibilities to an object dynamically, providing a flexible alternative to subclassing for extending functionality.Wraps object, extends same interface
Facadeβ­β˜†β˜† (1/3)β­β­β˜† (2/3)Provide a simplified, unified interface to a complex subsystem.High-level wrapper methods
Flyweight⭐⭐⭐ (3/3)β­β˜†β˜† (1/3)Use sharing to support large numbers of fine-grained objects efficiently.Flyweight pool returning existing instances
Proxyβ­β­β˜† (2/3)β­β˜†β˜† (1/3)Provide a surrogate or placeholder for another object to control access to it.Same interface, intercepts requests

Behavioral Patterns at a Glance

PatternComplexityPopularityIntentKey Mechanism
Chain of Responsibilityβ­β­β˜† (2/3)β­β­β˜† (2/3)Pass a request along a chain of handlers. Each handler decides to process the request or pass it to the next handler.Linked handlers with next reference
Commandβ­β˜†β˜† (1/3)⭐⭐⭐ (3/3)Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.Command object with execute()/undo()
Interpreter⭐⭐⭐ (3/3)β­β˜†β˜† (1/3)Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.Syntax tree of rule expressions
Iteratorβ­β­β˜† (2/3)⭐⭐⭐ (3/3)Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation (list, stack, tree, etc.).Iterator interface with hasNext()/next()
Mediatorβ­β­β˜† (2/3)β­β­β˜† (2/3)Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.Mediator interface coordinates colleagues
Memento⭐⭐⭐ (3/3)β­β˜†β˜† (1/3)Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later.Memento stores internal state snapshot
Observerβ­β­β˜† (2/3)⭐⭐⭐ (3/3)Define a one-to-many dependency so that when one object changes state, all its dependents are notified and updated automatically.Subject maintains observer list
Stateβ­β˜†β˜† (1/3)β­β­β˜† (2/3)Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.State classes encapsulate context behaviors
Strategyβ­β˜†β˜† (1/3)⭐⭐⭐ (3/3)Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.Composition with strategy interface
Template Methodβ­β˜†β˜† (1/3)β­β­β˜† (2/3)Define the skeleton of an algorithm in a superclass, letting subclasses override specific steps without changing the algorithm's structure.Abstract class with final template method
Visitor⭐⭐⭐ (3/3)β­β˜†β˜† (1/3)Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.Double dispatch pattern

Design Patterns vs Design Principles

ConceptWhat It IsExamples
Design PrincipleGeneral guideline for writing good codeSOLID, DRY, KISS, YAGNI
Design PatternSpecific, proven solution template for a recurring problemSingleton, Factory, Observer

Patterns often implement one or more principles β€” for example, the Strategy pattern applies the Open/Closed Principle and Dependency Inversion.


When to Use Design Patterns

  • DO use patterns when you recognize a recurring design problem they solve
  • DO use patterns to communicate intent clearly with your team
  • DON'T force patterns into every problem β€” simplicity beats cleverness
  • DON'T over-engineer with patterns when a straightforward solution works

"Design patterns should be used to simplify code, not to complicate it."


Advanced Editorial Pass: Pattern Selection Under Real Constraints

Architectural Decision Heuristics

  • Start with volatility analysis: which part of the design is likely to change first (creation, composition, or behavior)?
  • Select the lightest pattern that isolates that volatility; avoid introducing extension points with no credible change pressure.
  • Evaluate operational impact early: observability, failure isolation, and debugging complexity matter as much as class design elegance.

Common Misuse Signals

  • A pattern is chosen before a concrete pain point exists.
  • Teams use pattern names as status signals instead of problem-solution language.
  • The implementation increases indirection but does not reduce coupling or change risk.

Senior-Level Review Questions

  1. Which design axis are we trying to stabilize: construction, structure, or runtime behavior?
  2. What is the expected cost of removing this pattern in 6 months if requirements simplify?
  3. Does this pattern improve deploy-time and run-time operability, or only source-level aesthetics?

Compare Next

πŸ“–
Track Page Progress0 / 635 Read
Knowledge Base Completion0%