Design patterns are reusable solutions to problems that occur frequently in software design. They are not finished pieces of code you paste in — they are blueprints, templates for solving a class of problem. A pattern describes the problem, explains why naive solutions fail, and gives you a proven structure that works. Patterns emerged from Christopher Alexander's architecture work and were brought into software by the "Gang of Four" (Gamma, Helm, Johnson, Vlissides) in their 1994 book "Design Patterns: Elements of Reusable Object-Oriented Software".
The Gang of Four classified all 23 patterns into three categories based on their purpose. Creational patterns handle object creation. Structural patterns handle how objects are composed into larger structures. Behavioural patterns handle communication and responsibility between objects. Understanding which category a pattern belongs to immediately tells you what problem it is solving.
Creational — Object Creation
Structural — Object Composition
Behavioural — Object Communication
Several patterns share surface-level similarities — they both wrap objects, or they both define interfaces — but solve fundamentally different problems. The following comparisons clarify the intent behind each pair or group.
The Principles Patterns Apply
Where You See Patterns Every Day
// ── Observer ─────────────────────────────────────────────────────
@EventListener
public void onOrderPlaced(OrderPlacedEvent event) { ... }// ── Proxy (@Transactional) ───────────────────────────────────────
@Transactional
public void transferFunds(Account from, Account to, BigDecimal amount) { ... }// ── Template Method ──────────────────────────────────────────────
JdbcTemplate.query(sql, rowMapper);
// ── Decorator (java.io) ──────────────────────────────────────────
new BufferedReader(new InputStreamReader(socket.getInputStream()));
// ── Strategy ─────────────────────────────────────────────────────
list.sort(Comparator.comparing(Person::getName));