skip to content

Design Patterns

The Gang of Four vocabulary for recurring object designs, split into creational, structural and behavioral. For each pattern you learn its intent, structure, when it applies and how it degrades when overused — and interviews use them as a shared shorthand for describing designs.

part ofSoftware design & architectureoverview, primer and where to startread it →
on this pageshow

explore

questions

183 · 4 sections

What problem does the Abstract Factory design pattern solve, and what does it mean that it creates a "family" of objects?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Abstract Factory gives you one interface with several creation methods that together produce a set of related objects. Client code asks the interface for parts and never names concrete classes, so swapping one factory swaps the whole matching set.

open as a page

What problem does the Builder design pattern solve, and how is it better than a constructor that takes many parameters?

level: juniorimportance: must knowfreq 78%
basics
~20 s

Builder replaces a long constructor argument list. You set values one named step at a time, skipping the ones you do not need, then call build() to get the finished object. It is easier to read and harder to mix arguments up.

open as a page

What problem do creational design patterns (Singleton, Factory Method, Abstract Factory, Builder, Prototype) solve, and what do they all have in common?

level: juniorimportance: must knowfreq 72%
basics
~20 s

They separate creating an object from using it. Instead of calling a concrete constructor directly, code asks something else to produce the object — so the system can change which class is built, and how, without editing every caller.

open as a page

What is the Factory Method design pattern, and what problem does it solve?

level: juniorimportance: must knowfreq 78%
basics
~20 s

Factory Method hides object creation behind an overridable method. Code that needs an object calls that method instead of naming a concrete class directly, and a subtype (or implementation) decides which concrete class actually gets built.

open as a page

What problem does the Object Pool creational pattern solve, and what is the acquire/use/release lifecycle of a pooled object?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Some objects are slow or costly to create — database connections, threads, sockets, large buffers. An Object Pool keeps a fixed set of them alive and ready. Callers borrow one, use it, then give it back instead of creating and destroying it each time.

open as a page

What problem does the Adapter design pattern (Gang of Four, structural category) solve, and what are its participants?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Adapter converts one type's interface into the interface a caller already expects, so two otherwise incompatible pieces of code can work together. The adapter wraps the existing type and translates each call, without changing either side.

open as a page

What problem does the Bridge design pattern solve, and how does its structure solve it?

level: juniorimportance: must knowfreq 55%
basics
~20 s

Bridge splits a design into two separate hierarchies — an abstraction (what the thing is) and an implementation (how it does its work) — connected by a reference instead of inheritance, so each side can grow independently.

open as a page

What problem does the Composite design pattern solve, and what does it mean for a client to treat an individual object and a group of objects "uniformly"?

level: juniorimportance: must knowfreq 68%
basics
~20 s

Composite arranges objects into part-whole trees. A single item and a group of items implement the same interface, so client code calls the same method on either one and never has to check which it is.

open as a page

What is the Decorator design pattern, and why is it called a flexible alternative to subclassing for adding behavior to an object?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Decorator wraps an object inside another object that implements the same interface. The wrapper adds behavior before or after passing the call to the wrapped object. You add features by composing wrappers at runtime instead of writing subclasses.

open as a page

What problem does the Facade design pattern solve, and what does a facade actually add to a system?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Facade puts one simple, higher-level object in front of a complicated group of classes. Clients call the facade instead of wiring the parts together themselves, so calling code is shorter and depends on fewer internal types.

open as a page

In the Gang of Four design pattern classification, what problem space do behavioral patterns address, and how do they differ from creational and structural patterns?

level: juniorimportance: must knowfreq 72%
basics
~10 s

Behavioral patterns describe how objects talk to each other and who is responsible for what. Creational patterns are about how objects get made; structural patterns are about how objects are composed into bigger shapes.

open as a page

What is the Chain of Responsibility design pattern, and what coupling problem between a request's sender and its receiver does it solve?

level: juniorimportance: must knowfreq 70%
basics
~20 s

Chain of Responsibility links several handler objects in a sequence. The sender passes a request to the first handler; each one either handles it or forwards it onward. The sender never knows which handler ultimately responds.

open as a page

What is the Command design pattern, and what are the responsibilities of the invoker, the command object, and the receiver?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Command turns a request into an object. The command holds what to do plus the data needed. The invoker (button, queue, scheduler) just calls execute() without knowing the receiver — the object that actually performs the work.

open as a page

What is the intent of the Interpreter design pattern, and what kind of problem is it a good fit for?

level: juniorimportance: must knowfreq 25%
basics
~20 s

Interpreter gives a small language a class per grammar rule, each with an interpret operation. A sentence is turned into a tree of these objects, and evaluating the tree executes the sentence. Best for small, stable mini-languages.

open as a page

What problem does the Iterator design pattern solve, and what does "without exposing the underlying representation" mean in its intent?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Iterator gives a standard way to walk a collection's elements one at a time. The collection hands you a small cursor object with "is there more?" and "give me the next one" operations, so you never touch its internal array, nodes, or indexes.

open as a page

What is the "god object" anti-pattern in software design, and why is it considered harmful?

level: juniorimportance: must knowfreq 62%
basics
~20 s

A god object is one class that knows and does almost everything: data, rules, coordination, I/O. Because everything depends on it and every feature edits it, it is hard to understand, hard to test, and a constant source of conflicts and bugs.

open as a page

What is the difference between a design pattern and a language idiom?

level: juniorimportance: must knowfreq 55%
basics
~20 s

A design pattern is a language-neutral solution shape for a recurring design problem, like Observer or Strategy. An idiom is a small, language-specific way of writing something well, like C++ RAII or Python comprehensions. Patterns travel between languages; idioms usually do not.

open as a page

What does "refactoring to patterns" mean, and why is introducing a design pattern through refactoring often preferred over choosing patterns up front?

level: juniorimportance: must knowfreq 58%
basics
~20 s

It means you don't pick patterns before writing code. You write the simplest thing that works, and when the code starts to smell (duplication, a growing conditional), you refactor in small behavior-preserving steps until a known pattern emerges. The smell justifies the pattern.

open as a page

How should you decide which design pattern to use in a given situation, and why do experienced engineers insist you start from the problem rather than from the pattern catalogue?

level: juniorimportance: must knowfreq 62%
basics
~20 s

Start from the concrete problem: what varies, what must stay stable, what change you expect. Then look for a pattern whose stated intent restates that problem. Choosing a pattern first and bending code to fit it adds complexity without solving anything.

open as a page

Why is heavy use of the Singleton pattern (a class exposing one globally reachable shared instance, typically via a static accessor) often treated as an anti-pattern?

level: middleimportance: must knowfreq 68%
basics
~20 s

Because a singleton is global mutable state with a static access point. Callers reach it directly instead of declaring it, so dependencies are hidden, tests share and leak state between each other, substitution for fakes is hard, and lifetime/threading rules become implicit.

open as a page