Skip to content

design pattern

A design pattern is a general, reusable solution to a problem that comes up repeatedly in software design. A pattern is not finished code to drop into a program but a template for arranging classes and objects, so the same idea can be adapted to many situations rather than copied verbatim.

A design pattern operates at a higher level of abstraction than an algorithm. Rather than prescribing an exact sequence of steps, a pattern describes the shape of a solution and the roles its parts play, leaving the concrete code open. Naming these recurring shapes gives developers a shared vocabulary, so a single word such as “observer” or “factory” can stand for a whole arrangement of collaborating components.

Much of that vocabulary comes from the 1994 book Design Patterns: Elements of Reusable Object-Oriented Software, whose four authors are known as the Gang of Four. It catalogs 23 patterns in three families:

The Gang of Four's 23 patterns split into three families, Creational, Structural, and Behavioral, each with example patterns.
The Three Gang of Four Pattern Families
  • Creational patterns control how objects come into being, keeping that logic separate from the code that uses the result. Examples include Factory Method, Builder, and Singleton.
  • Structural patterns describe how objects and classes combine into larger structures, often through composition or inheritance. Examples include Adapter, Decorator, and Proxy.
  • Behavioral patterns address how objects communicate and divide responsibility. Examples include Observer, Strategy, and Iterator.

The idea predates that book. Architect Christopher Alexander introduced patterns for building design in 1977, and Kent Beck and Ward Cunningham carried the approach into software in 1987.

A common critique is that some patterns mainly compensate for features a language lacks, since several of them dissolve into ordinary code once a language offers first-class functions or a built-in iterator protocol. Strategy is the standard example: where a stricter language needs a family of classes, Python often passes a single function as an argument.

Applied without need, patterns can also add indirection that obscures a design rather than clarifying it.

OOP in Python 3

Tutorial

Object-Oriented Programming (OOP) in Python

In this tutorial, you'll learn all about object-oriented programming (OOP) in Python. You'll learn the basics of the OOP paradigm and cover concepts like classes and inheritance. You'll also see how to instantiate an object from a class.

intermediate python

For additional information on related topics, take a look at the following resources:


By Martin Breuss • Updated Aug. 14, 2026