How This Book Is Organized

After the introduction in Chapter 1, the book takes a tour through the 23 core design patterns. Each chapter discusses two or three patterns, chosen because they have some common applicability and can be compared at the end of the chapter. The patterns are subdivided into three groups: structural, creational, and behavioral.

We begin with the structural patterns, studying the Decorator, Proxy, and Bridge patterns in Chapter 2; the Composite and Flyweight patterns in Chapter 3; and the Adapter and Façade patterns in Chapter 4. We then move on to the creational patterns, exploring the Prototype, Factory Method, and Singleton patterns in Chapter 5 and the Abstract Factory and Builder patterns in Chapter 6. The last four chapters deal with the largest category, the behavioral patterns: Chapter 7 focuses on the Strategy, State, and Template Method patterns; Chapter 8 on the Chain of Responsibility and Command patterns; Chapter 9 on the Iterator, Mediator, and Observer patterns; and Chapter 10 on the Visitor, Interpreter, and Memento patterns.

Our discussion of each pattern will consist of the following parts:

Role

A short, high-level description of the pattern and what it is meant to achieve

Illustration

An example of where the pattern might be used in programming a modern computer system, illustrating a real-world context with a photo or diagram to help you remember the pattern

Design

An identification of the interconnected players in the pattern and their roles, explained in a UML diagram, with links back to the key players in the illustration

Implementation

A stepwise refinement development of a short program that illustrates the pattern using the terms introduced in the "Design" section

Example

A second program that gives an example of the pattern, usually in terms of the illustrative example, where the programming moves away from a strict adherence to the pattern terms

Use

A discussion of real-world scenarios where the pattern might be used, ending with a table listing the conditions that would make its use applicable

Exercises

A list of exercises of differing degrees of difficulty designed to enhance your understanding of the pattern under discussion

At the end of each chapter you will find a comparison of the patterns discussed therein and a discussion of how they fit in with those that have gone before.

The ordering of the patterns has been carefully chosen so as to represent a gradual progression in C# 3.0 maturity. Implementing the earlier patterns in each section requires very little that is not available in C# 1.0, while the later patterns are more sophisticated in their implementation and take advantage of more advanced features present in C# 3.0. This approach allows new features to be introduced inline, as they become relevant, rather than all at once at the start or end of the text.

This book is not intended to be a reference guide to the whole of C# or even C# 3.0, but rather to be a practical guide to using the most interesting features of the language. Although the emphasis is on developments in the most recent version, I also pick out some features of C# 1.0 and 2.0 that I think are really useful but that are not often employed in code. The list of C# features explicitly covered follows this Preface.

Special features of this book include:

  • Pictorial illustrations of patterns, to help you focus on the meaning of what each pattern can accomplish in real life

  • Quizzes that relate the illustrations to the UML diagrams

  • Uncluttered "theory" code that can be adapted to many situations

  • Tables that give guidance on when to choose a specific pattern

  • Comparison tables for patterns that are similar, showing how they differ

  • Lists of the advantages, disadvantages, and limitations of each pattern

  • Challenges and exercises to help you take your knowledge further

Get C# 3.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.