Chapter 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Appendix


Note: Example 2.6 has a local update below, not included in these zip files yet

Download all the programs (76KB) in text format

Download images for Example 3.4 (14 MB)

Download all the programs as Visual Studio projects (1 MB)


  1. Some of the examples in the chapters make use of images or data files. These should be preloaded into the same directory as the program file in order for the program to run correctly. 
  2. The formatting of the programs might differ slightly from that in the book, due to the typographic process.
  3. In the Visual Studio versions of most programs, a Console.Readkey() call has been inserted as the last statement so that the output remains visible for inspection. Typing any key will close the Console window.

Chapter 2 Structural Patterns: Decorator, Proxy, and Bridge

2.1 Decorator pattern theory code (decorator-theory.cs)
2.2 Decorator pattern example code - Photo Decorator (decorator-photo.cs, jug.jpg)
2.3 Proxy pattern theory code (proxy-theory.cs)
2.4 Proxy pattern example code - SpaceBook (proxy-spacebook.cs)
2.5 Bridge pattern theory code (bridge-theory.cs)
2.6 Bridge pattern example code - OpenBook (bridge-openbook.cs)

Chapter 3 Structural Patterns: Composite and Flyweight

3.1 Composite pattern - namespace code (composite-theory-ns.cs)
3.2 Composite pattern - Photo Library sample run (composite.dat)
3.3 Composite pattern example code - Photo Library (composite-photolibrary.cs)
3.4 Flyweight pattern example - Photo Group including the FlyweightPattern namespace (flyweight-photogroup.cs, flyweight-theory-ns.cs)
     associated images - unzip first (flyweight-images.zip)

Chapter 4 Structural Patterns: Adapter and Façade

4.1 Adapter pattern theory code (adapter-theory.cs)
4.2 Two-way Adapter pattern example code - Seabird (adapter-twoway-seabird.cs)
4.3 Pluggable Adapter pattern theory code (adapter-pluggable-theory.cs)
4.4 and Appendix Pluggable Adapter pattern example code - MyCoolBook (adapter-pluggable-coolbook.cs)
4.5 Façade pattern theory code (facade-theory-main.cs, facade-theory-ns.cs)

Chapter 5 Creational Patterns: Prototype, Factory Method, and Singleton

5.1 Prototype pattern theory code - namespace (prototype-theory-ns.cs)
5.2 Prototype pattern theory code (prototype-theory-main.cs)
Appendix Prototype pattern - Photo archive (prototype-photoarchive.cs  prototype.dat)
5.3 Factory Method pattern example code (factorymethod-avocados.cs)
5.4 Singleton pattern theory code (singleton-theory.cs)
5.5 Singleton pattern - lazy instantiation (singleton-theory-lazy.cs)
5.6 Singleton pattern generic code (singleton-theory-lazy-generic.cs)

Chapter 6 Creational Patterns: Abstract Factory and Builder

6.1 Abstract Factory pattern example code (abstractfactory-bags.cs)
6.2 Builder pattern theory code (builder-theory.cs)
6.3 Builder pattern example code (builder-bags.cs)

Chapter 7 Behavioural Patterns: Strategy, State, and Template Method

7.1 Strategy pattern theory code (strategy-theory.cs)
7.2 Strategy pattern example code - Sorting Animator (strategy-sorting.cs)
7.3 State pattern theory code (state-theory.cs)
7.4 State pattern example code - RPC game (state-game.cs)
7.5 Template Method pattern theory code (templatemethod-theory.cs)

Chapter 8 Behavioral Patterns: Chain of Responsibility and Command

8.1 Chain of Responsibility pattern theory code (chain-theory.cs, chain-theory-exception.cs)
8.2 Chain of Responsibility pattern example code - Trusty Bank (chain-bank.cs)
8.3 Command pattern theory code (command-theory.cs)
8.4 Command pattern theory code - multireceiver version (command-multiReceiver.cs)
8.5 Command pattern example code - menu handler (command-pastePrint.cs)

Chapter 9 Behavioral Patterns: Iterator, Mediator, and Observer

9.1 Iterator pattern theory code (iterator-theory.cs)
9.2 Iterator pattern LINQ code (iterator-linq.cs)
Appendix Iterator pattern - Family tree (iterator-familytree.cs)
9.3 Mediator pattern theory code (mediator-theory.cs)
9.4 Mediator pattern example code - chat room (mediator-chatroom.cs)
9.5 Observer pattern theory code (observer-theory.cs)
Appendix: Observer pattern - Blogs (observer-blogs.cs)

Chapter 10 Behavioral Patterns: Visitor, Interpreter, and Memento

10.1 Visitor pattern theory code (visitor-theory.cs)
10.2 Visitor pattern example code - course marks (visitor-course.cs)
Appendix: Visitor theory - reflection (visitor-theory-reflection.cs)
Appendix: Interpreter - Course structure (interpreter-course.cs)
Appendix: Interpreter pattern - Mirrors (interpreter-mirrors.cs    calc_winforms.xml)
10.3 Memento pattern theory code (memento-theory.cs)
10.4 Memento pattern example code - TicTacToe (memento-example.cs)


Adapter pattern pluggable - Coolbook (adapter-pluggable-coolbook.cs)
Prototype pattern - Photo archive (prototype-photoarchive.cs  prototype.dat)
Iterator pattern - Family tree (iterator-familytree.cs)
Observer pattern - Blogs (observer-blogs.cs)
Visitor theory - reflection (visitor-theory-reflection.cs)
Interpreter - Course structure (interpreter-course.cs)
Interpreter pattern - Mirrors (interpreter-mirrors.cs    calc_winforms.xml)


Chapter 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Appendix