CONTENTS
Foreword xi
by Eric Lippert, Senior Developer, C# Compiler Team, Microsoft, Redmond.
Preface xv
Why I wrote this book xv
Who this Book is For xvi
What You Need to Know xvi
How this Book is Organised xvii
What You Need To Use this Book xviii
Finding What You Need xix
Conventions Used in The Book xix
Using Code Examples xix
Comments And Questions xx
Acknowledgments xxi
1. C# Meets Design Patterns 1
About Patterns 2
About UML 3
About C# 3.0 5
About the Examples 6
2. Structural Patterns:
Decorator, Proxy, and Bridge 8
Decorator Pattern 9
Proxy Pattern 22
Bridge Pattern 36
Example: OpenBook 39
Pattern Comparison 46
3. Structural Patterns: Composite and Flyweight 45
Composite Pattern 49
Flyweight Pattern 61
Exercises 72
Pattern Comparison 72
4. Structural Patterns: Adapter and Façade 74
Adapter Pattern 74
Façade Pattern 93
Pattern Comparison 99
5. Creational Patterns: Prototype, Factory Method, and
Singleton 101
Prototype Pattern 101
Factory Method Pattern 110
Singleton Pattern 115
Pattern Comparison 120
6. Creational Patterns: Abstract Factory and Builder 122
Abstract Factory Pattern 122
Builder Pattern 129
Pattern Comparison 137
7. Behavioral Patterns: Strategy, State, and Template Method 139
Strategy Pattern 139
State Pattern 148
Template Method Pattern 158
Pattern Comparison 162
8. Behavioral Patterns: Chain of Responsibility and Command 164
Chain of Responsibility Pattern 164
Command Pattern 175
Pattern Comparison 186
9. Behavioral Patterns: Iterator, Mediator, and Observer 188
Iterator Pattern 188
Mediator Pattern 200
Observer Pattern 210
Pattern Discussion and Comparison 217
10. Behavioral Patterns: Visitor, Interpreter, and Memento 220
Visitor Pattern 220
Interpreter Pattern 233
Memento Pattern 242
Pattern Comparison 252
11. The Future of Design Patterns 253
Summary of Patterns 253
A Future for Design Patterns 256
Concluding Remarks 258
Appendix 259
Bibliography 283
Index 285