Skip to main content
Advertisement

17.1 Design Patterns Overview

Design patterns are proven solutions to recurring problems in software development. Like architectural blueprints, they provide reusable code structures and design ideas for similar situations.

The 23 patterns cataloged by the Gang of Four (GoF) in their 1994 book "Design Patterns: Elements of Reusable Object-Oriented Software" are the industry standard, organized into three categories.

1. Why Learn Design Patterns?

  1. Common vocabulary: "Let's use the Singleton pattern here" quickly communicates intent to teammates.
  2. Proven solutions: Avoid solving from scratch problems that countless developers have already solved.
  3. Maintainability: Code following patterns is resilient to change and extension.
  4. Job interviews: Design patterns are a staple topic in backend developer interviews.

2. Three Categories

CategoryPurposeKey Patterns
CreationalEncapsulate object creationSingleton, Factory Method, Builder, Prototype, Abstract Factory
StructuralCompose classes/objects into larger structuresAdapter, Decorator, Proxy, Facade, Composite
BehavioralDistribute responsibility and collaboration between objectsStrategy, Observer, Template Method, Command, Iterator

3. Design Patterns in the Java Standard Library

PatternJava Standard Library Example
SingletonRuntime.getRuntime(), System
Factory MethodCalendar.getInstance(), List.of()
BuilderStringBuilder, Stream.Builder
IteratorIterator<E>, for-each loop
ObserverEventListener
StrategyComparator<T>, Runnable
DecoratorBufferedReader, Collections.unmodifiableList()
Proxyjava.lang.reflect.Proxy
AdapterArrays.asList(), InputStreamReader
Advertisement