SWDev Impl Patterns

SWDev Impl Patterns: Prologue

overview, sources, story content

0.0 What are Implementation Patterns?

Implementation patterns are micro-level idioms for writing code that is clear, correct, and easy to modify. Unlike architectural patterns - which describe how components are organized - implementation patterns operate at the method, class, and expression level. They answer questions like: how long should a method be, how should it be named, when should a temporary variable be introduced, and how should conditionals be structured? The primary sources for this story are Kent Beck's Implementation Patterns (2008) and Martin Fowler's Refactoring: Improving the Design of Existing Code (2018). Beck focuses on patterns that make code communicate intent clearly; Fowler catalogs the transformations that move code toward those patterns. Together they form a practical vocabulary for writing code that is easy to read and safe to change. These patterns apply across languages. The idioms are illustrated here in the four languages used throughout this site - Rust, C++, C#, and Python - because the right form of each pattern varies with language features.

0.1 Sources

Key Sources
SourceContribution
Kent Beck - Implementation Patterns Patterns at the class and method level: Composed Method, Intention-Revealing Name, Value Object, Guard Clause, Collecting Parameter, Method Object, Command/Query separation. Beck's central thesis is that code communicates to future readers, and patterns are the vocabulary for doing that well.
Martin Fowler - Refactoring A catalog of transformations that move code toward clean implementation patterns. Extract Method, Introduce Explaining Variable, Replace Conditional with Polymorphism, Replace Temp with Query, and Null Object are among the most frequently applied. Fowler shows that patterns are destinations; refactoring is the path.
Bertrand Meyer - Object-Oriented Software Construction Origin of Command-Query Separation: a method either returns a value (query) or changes state (command), not both. This single principle prevents a class of subtle bugs.
GoF - Design Patterns Template Method and Null Object, covered here at the implementation level, are formally GoF patterns. See the Design Patterns story for a fuller treatment of GoF patterns.

0.2 Pattern Overview

The twelve patterns in this story fall into three groups:
Pattern Summary
PatternChapterProblem addressed
Composed Method1 Methods that do too much at too many levels of abstraction.
Intention-Revealing Name1 Names that describe implementation rather than purpose.
Explaining Variable1 Complex expressions that cannot be understood without tracing values.
Guard Clause1 Deep nesting caused by handling the normal case before the error cases.
Value Object2 Objects representing quantities where identity is irrelevant.
Null Object2 Null/nil checks scattered across callers of a method.
Collecting Parameter2 Results assembled through recursive or multi-step traversal.
Method Object2 Complex methods with many local variables and multiple conceptual steps.
Command-Query Separation3 Methods that both return values and cause side effects.
Replace Conditional with Polymorphism3 Type-dispatching conditionals repeated across multiple methods.
Delegation over Inheritance3 Subclasses that differ primarily in behavior, not in type identity.
Template Method3 Algorithms with a stable skeleton and interchangeable steps.

0.3 Story Content

  1. Clarity and Structure

    Composed Method, Intention-Revealing Name, Explaining Variable, Guard Clause - patterns that make individual methods readable at a glance.
  2. Objects and State

    Value Object, Null Object, Collecting Parameter, Method Object - patterns that shape how state is held and how computation accumulates results.
  3. Behavior and Dispatch

    Command-Query Separation, Replace Conditional with Polymorphism, Delegation over Inheritance, Template Method - patterns that clarify how objects communicate and vary their behavior.

0.4 References

References
ResourceDescription
Kent Beck - Implementation Patterns The primary source for this story. Covers class, state, and behavior patterns at the method and expression level.
Martin Fowler - Refactoring Catalog of refactoring transformations that move code toward cleaner implementation patterns. Second edition (2018) uses JavaScript.
Refactoring Guru - Catalog Illustrated refactoring catalog cross-referencing Fowler's techniques with examples in multiple languages.
Design Patterns story GoF design patterns - the structural, behavioral, and creational patterns that operate at a higher level than implementation patterns.