Skip to content

Design Patterns Overview

Design patterns are reusable solutions to commonly occurring problems in software design. They’re not code you copy — they’re templates for solving problems in a particular context.

First catalogued by the “Gang of Four” (Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides) in their 1994 book Design Patterns: Elements of Reusable Object-Oriented Software.

Deal with object creation — how objects are instantiated.

Pattern Problem Solved
Singleton Ensure only one instance of a class exists
Factory Method Let subclasses decide which class to instantiate
Abstract Factory Create families of related objects
Builder Construct complex objects step by step
Prototype Clone existing objects

Deal with object composition — how objects are assembled from parts.

Pattern Problem Solved
Adapter Make incompatible interfaces work together
Decorator Add behaviour to objects without subclassing
Facade Simplify a complex subsystem with a unified interface
Proxy Control access to an object
Composite Treat individual objects and groups uniformly
Bridge Decouple abstraction from implementation

Deal with communication between objects — how they interact and distribute responsibility.

Pattern Problem Solved
Strategy Define a family of algorithms and make them interchangeable
Observer Notify dependents when an object changes state
Command Encapsulate a request as an object
Chain of Responsibility Pass a request along a chain of handlers
Template Method Define a skeleton algorithm, defer steps to subclasses
Repository Abstract data access from business logic (an enterprise pattern from Fowler’s PoEAA, not one of the 23 GoF patterns)
Iterator Traverse a collection without exposing its structure
Page Patterns
Creational patterns Singleton, Factory Method, Abstract Factory, simple factory with keyed services, Builder
Structural and behavioral patterns Adapter, Decorator, Repository, Strategy, Observer

Each guide has runnable C# samples, pitfalls and interview questions.

Patterns solve recurring problems. Apply them when:

  • You recognise the problem they address
  • The solution without a pattern would be complex or brittle
  • Team members will understand the pattern

Don’t apply patterns speculatively — “I might need this later” leads to over-engineering. YAGNI (You Aren’t Gonna Need It) applies.

Many patterns are built into modern languages and frameworks:

  • Observer → React’s useEffect, event emitters, RxJS
  • Strategy → function arguments, dependency injection
  • Decorator → Python decorators, TypeScript decorators, middleware
  • Repository → Entity Framework, Prisma, SQLAlchemy
  • Factory → dependency injection containers

Recognising patterns in frameworks helps you use them more effectively.

Design patterns often implement SOLID principles:

Principle Description
Single Responsibility A class should have one reason to change
Open/Closed Open for extension, closed for modification
Liskov Substitution Subtypes must be substitutable for base types
Interface Segregation Clients shouldn’t be forced to depend on unused interfaces
Dependency Inversion Depend on abstractions, not concretions