SWDev Patterns

SWDev Patterns: Prologue

overview, categories, language idioms

0.0 What are Design Patterns?

Design patterns are recurring solutions to common design problems - vocabulary shared among experienced developers. A pattern is not code you copy; it is a named, well-understood approach you apply in your own context. The term was popularized by the Gang of Four (GoF) book Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, Helm, Johnson, Vlissides, 1994). The book catalogued 23 patterns in three categories. The patterns remain relevant, though the way each language expresses them has evolved considerably since then. This story focuses on idiomatic expression: applying each pattern in the style natural to the language at hand, rather than mechanically transcribing the original Java class diagrams. A Strategy in Rust looks nothing like a Strategy in the GoF book, yet solves exactly the same problem.

0.1 Pattern Categories

The GoF patterns fall into three categories based on the concern they address:
GoF Pattern Categories
CategoryConcern
Behavioral How objects communicate, distribute responsibility, and exchange information. Patterns: Strategy, Observer, Command, Iterator, Template Method, Chain of Responsibility, and others.
Creational How objects are created, decoupling object creation from the code that uses them. Patterns: Factory Method, Abstract Factory, Builder, Prototype, Singleton.
Structural How objects and classes are composed into larger structures. Patterns: Decorator, Adapter, Composite, Proxy, Facade, Bridge, Flyweight.
This story covers the most commonly encountered patterns in each category. Structural patterns here are design-level (object composition), distinct from the architectural structural patterns - monolithic, data flow, factored - covered in SWDevStory: Structural Patterns.

0.2 Language Idioms

The GoF book used C++ and Smalltalk. Most later literature uses Java. Modern languages provide constructs that change how patterns are expressed and sometimes eliminate the need for a dedicated pattern class entirely:
Pattern Expression by Language
LanguageKey idioms for pattern expression
Rust Traits and trait objects replace abstract base classes. Enums with associated data replace class hierarchies for sum types. Closures replace single-method strategy objects. The ownership model eliminates most Observer pitfalls around object lifetime.
C++ Abstract base classes with virtual functions for classic patterns. Templates and type parameters for compile-time Strategy. Lambdas and std::function for lightweight Command and Observer. RAII resource management interacts with Singleton and Factory lifetime decisions.
C# Interfaces and delegates cover most behavioral patterns. Events and delegates are the native form of Observer. Extension methods provide Decorator-like behavior without subclassing. Generics replace many use cases that required Prototype in early Java.
Python Duck typing: any object implementing the right methods works as a strategy. First-class functions replace most single-method classes. The @decorator syntax is a direct language feature for the Decorator pattern. Generators implement Iterator natively without a separate class.
Each chapter shows the pattern in language-agnostic pseudocode, then notes the idiomatic form in each of the four languages covered in this site.

0.3 Story Content

The chapters cover the most widely used patterns in each category:
  1. Behavioral Patterns

    Strategy, Observer, and Command - the patterns most frequently encountered in application and library design.
  2. Creational Patterns

    Factory Method, Builder, and Singleton - controlling how objects come into existence and managing their lifetime.
  3. Structural Patterns

    Decorator, Adapter, and Composite - composing objects to extend, bridge, or unify behavior.

0.4 References

Design Patterns References
ResourceDescription
Refactoring Guru - Design Patterns Illustrated catalog of all GoF patterns with examples in multiple languages.
OODesign.com Pattern descriptions with UML class diagrams and concise explanations.
SWDevStory: Structural Patterns Architectural structural patterns - monolithic, data flow, factored.
SWDevStory: Advanced Patterns Type erasure and plugin architectural patterns.