Chapters

The whole book, in order.

Fifteen parts, read in order the first time through, with a set of appendices behind them. Each chapter also stands on its own for a reader jumping in to solve one problem. Pick a part, or start at the top.

Part 0 Orientation

The toolchain (.NET 10 SDK, dotnet CLI, xUnit, NSubstitute), how to read the book, and the codetabs convention that sets modern C# idioms side by side.

  1. Prerequisites and the toolchainThe .NET 10 SDK, dotnet CLI, xUnit, and NSubstitute toolchain the examples build against on Fedora, how the example harness works with no containers, and why every code sample is a single idiomatic C# 14 block.

Part 1 Why This Is Not a GoF Retelling

Patterns as decisions under forces, and the claim that several 1994 catalogue entries are now C# language features rather than designs you write.

  1. Patterns as decisions under forcesReframing the catalogue from a taxonomy to a set of decisions made under competing forces, with shipment rating as the running example.
  2. What 1994 assumed, and what C# invalidatedThe object-orientation assumptions the Gang of Four wrote under, and which of them C# has since turned into language features.

Part 2 What Modern C# Changes About the Catalogue

The feature map up front: event, delegates, yield and LINQ, nullable reference types, extension members, expression trees, source generators, reified generics, static abstract members, and value types, the modern C# 14 features that reshape how the Gang of Four catalogue reads against its 1994 assumptions.

  1. The divergence mapevent, delegates, yield and LINQ, nullable reference types, extension members, expression trees, source generators, reified generics, static abstract members, and value types, each named with a forward reference to the chapter that develops it.
  2. Naming patterns for teams and AI assistantsWhy a shared pattern vocabulary is a review tool for a team and for an AI assistant, and how naming cuts across the consignment lifecycle.

Part 3 Principles

SOLID in idiomatic C#, including dependency inversion where the DI container ships in the base class library.

  1. SRP, OCP, and LSPThe first three SOLID principles in idiomatic C#, taught by splitting one overloaded rate calculator.
  2. ISP, DIP, and DI with the built-in containerInterface segregation and dependency inversion where the dependency injection container ships in the base class library, ready to register and resolve with no separate framework decision to make.

Part 4 The .NET Substrate

The Dispose pattern and IAsyncDisposable, value types and Span, nullable reference types and records, and proving a design works with xUnit and NSubstitute before the patterns chapters begin.

  1. The Dispose pattern and IAsyncDisposableDispose(bool), finalizer interaction, using and await using, and the closest C# gets to RAII, specified by the Framework Design Guidelines.
  2. Value types: struct, readonly struct, and SpanWhen a value type is the right choice, and the C# 14 implicit span conversions that make Span ergonomic.
  3. NRTs, records, and init/required/withImmutability as a design tool, and why nullable reference types remove the motivation for the Null Object pattern.
  4. Proving it works: xUnit and NSubstituteThe testing baseline every later chapter uses, with xUnit for test structure and NSubstitute for collaborator substitution.

Part 5 Selecting and Varying Behaviour

Strategy, Template Method, State, and Command, and the delegate and keyed-service idioms that reshape them in C#.

  1. Strategy: delegates, interfaces, and keyed servicesThree levels of the same pattern: pass a Func, define an interface, or register keyed services, and when each is the right reach.
  2. Template Method and the delegate alternativeWhere an inheritance-based skeleton still fits, and where a delegate replaces it.
  3. State and finite state machinesA real state machine and a probabilistic variant, with pattern matching reshaping both.
  4. Command, undo, and Task-returning commandsDelegates as commands, reversible operations, and command queues that return Task.

Part 6 Creating Objects Under Control

Factory Method and Abstract Factory under reified generics, Builder displacement by required members and collection expressions, and Singleton as a DI lifetime.

  1. Factory Method and Abstract FactoryHow reified generics change these patterns, with typeof(T), constructor constraints, and type-keyed registries.
  2. Builder, required members, and Prototype with withWhy required members and collection expressions often beat a Builder, and Prototype as a one-line with expression.
  3. Singleton, Lazy, and DI lifetimesSingleton as a lifetime registration rather than a class trick, and where Lazy fits.

Part 7 Composing and Adapting Structure

Adapter, Facade, and Bridge with conversion operators, Decorator and Proxy through DI decoration and DispatchProxy, and Composite and Flyweight over repeated data.

  1. Adapter, Facade, and BridgeThe three structural adapters, plus C#'s implicit and explicit conversion operators.
  2. Decorator and ProxyDecorator and Proxy through DI decoration and DispatchProxy, and the attribute-versus-Decorator confusion.
  3. Composite and FlyweightComposite over nested structure, and Flyweight through interning, FrozenDictionary, and pooling.

Part 8 Coordinating and Traversing

Observer as the event keyword, Mediator and Chain of Responsibility as a pipeline, Iterator as a compiler-generated state machine, and Visitor, Memento, and Interpreter.

  1. Observer: the event keywordThe clearest case of a pattern dissolving into a language feature, and when to reach past event to IObservable.
  2. Mediator and Chain of ResponsibilityThe pipeline shape, with Kestrel middleware mentioned once as an illustration rather than a hosting subject.
  3. Iterator: yield return, LINQ, and IAsyncEnumerableThe pattern as a compiler-generated state machine, in its synchronous and asynchronous forms.
  4. Visitor, Memento, and InterpreterPattern matching as the Visitor alternative, and expression trees as the real Interpreter.

Part 9 Idiomatic C#

Extension members, expression trees, source generators, Roslyn analyzers, and static abstract members: the C# machinery behind the book's most research-heavy part.

  1. Extension methods and C# 14 extension membersExtension properties, static extension members, and operators, used to decorate or adapt a type you do not own.
  2. Expression trees: code as dataCode as inspectable data at runtime: how LINQ providers work, and how to build and inspect trees.
  3. Source generators: patterns at build timeReplacing reflection-based factories, registries, and mappers at build time, and the AOT and trimming argument.
  4. Roslyn analyzers: patterns enforced at compile timeEncoding a design rule as a build error, and the concrete landing point for the AI throughline.
  5. static abstract members and generic mathConstraining a generic over type-level operations with abstract static interface members and generic math over a custom value type.

Part 10 Patterns the Platform Defines

The Options pattern, Tester-Doer against the Result debate, and the Task-based Asynchronous Pattern: named patterns the .NET platform specifies in its own guidelines.

  1. The Options patternIOptions, IOptionsSnapshot, and IOptionsMonitor for configuration binding and change notification.
  2. Tester-Doer and the Result debateThe Framework Design Guidelines convention against the community Result, taught together, with the tradeoff stated rather than a side picked.
  3. TAP and the async conventionsThe Task-based Asynchronous Pattern named: naming, cancellation, and progress conventions, with mechanics left to the concurrency part.

Part 11 Concurrency Patterns

Patterns of usage rather than the async model: thread-safe creation, Active Object and Monitor Object on Channel, Producer-Consumer, pooling, and classic GoF patterns under concurrency.

  1. Why .NET chose stackless asyncThe framing chapter: green threads prototyped and rejected, and why that choice shapes every pattern that follows.
  2. Thread-safe creationLazy, a thread-safe Singleton, and why Double-Checked Locking is now a historical note.
  3. Monitor Object and Active Object on ChannelThe largest gap in the literature: POSA2's patterns re-expressed on async and Channel, where the language rejects Monitor Object at compile time and two participants dissolve into Task and await foreach.
  4. Producer-Consumer and pipelines as patternsProducer-Consumer at the pattern level, with the Channels mechanics left to the concurrency reference.
  5. Pools: object, connection, and ArrayPoolResource-management patterns for pooling connections and buffers that are scarce enough to matter.
  6. Classic GoF under concurrencyObserver across threads, Iterator as IAsyncEnumerable, Decorator over async, Command as Task, and immutability as a concurrency strategy.

Part 12 Patterns in the Wild

Shortcut patterns that are not anti-patterns, and the anti-patterns and pattern misuse to recognise, including pattern-shaped LLM output.

  1. Shortcut patternsDispatch tables, delegate maps, and FrozenDictionary: shortcuts that are not anti-patterns.
  2. Anti-patterns and pattern misuseService Locator, over-abstraction, and pattern-shaped LLM output: patterns applied past the point they pay for themselves.

Part 13 Changing Inherited Code

Seams where C# is non-virtual by default, the dependency-breaking techniques that follow, and the Fowler and Feathers contrast applied to C#.

  1. Seams in C#: non-virtual by defaultThe finding that inverts expectations: you cannot override to make a seam, so Feathers matters all the more in C#.
  2. Dependency-breaking techniquesInternalsVisibleTo, interface extraction, DI as a seam, and virtual as an explicit opt-in.
  3. Fowler vs Feathers, contrasted and combinedThe refactoring catalogue and the dependency-breaking catalogue, contrasted and combined on one engine.
  4. Refactor or rewriteThe judgement call, with criteria rather than a reflex.

Part 14 Putting It Together

A shipping-domain subsystem exercising patterns from every part, and a closing chapter on reviewing pattern-shaped output from AI and LLM tools.

  1. Final projectA shipping-domain subsystem exercising patterns from every part, built end to end.
  2. Working with AI and LLM toolsReviewing pattern-shaped LLM output, with the analyzer from the idiomatic-C# part as the enforcement mechanism.

Part 15 Appendices

A build and toolchain reference, an xUnit reference, an NSubstitute reference, an xUnit test-patterns guide, a pattern-to-force quick reference, a code-first review of programming principles, and the C# 15 / .NET 11 delta.

  1. Build and toolchain referenceA one-stop reference for building and testing every example: the pinned .NET 10 SDK, the dotnet CLI, Directory.Build.props, standalone versus whole-repository builds, the scripts/ helpers, and both editors.
  2. xUnit referenceA reference for the xUnit v3 test framework the examples are written against.
  3. NSubstitute referenceA reference for NSubstitute, the mocking library the examples use, with a note on Moq for readers on existing Moq codebases.
  4. xUnit test patternsThe four-phase test and test-double taxonomy from Meszaros, applied to xUnit and NSubstitute.
  5. Pattern-to-force quick referenceA quick reference mapping every pattern, principle, and idiom covered to the forces it answers.
  6. Programming principles reviewed in codeA code-first review of the wider programming-principle vocabulary beyond SOLID.
  7. C# 15 / .NET 11 deltaWhat the C# 15 and .NET 11 short-term-support release changes for each affected pattern and idiom, kept additive so the examples stay on C# 14.