PREFACE xiv
ACKNOWLEDGMENTS xix
1 Why Learn Design Patterns and Why Do So with Help from Harry Potter? 1
1.1 The OO Design Patterns "Bible" by GoF 2
1.2 But What Has Harry Potter Got to Do with OO Design Patterns? 4
1.3 Is Familiarity with Harry Potter a Requirement for Understanding This Book? 6
1.4 How the Pattern Explanations are Organized 7
1.5 The Terminology of Object-Oriented Programming 7
1.6 The UML Notation Used in the Class Diagrams 12
1.6.1 Association as a Relationship Between Classes 14
1.6.2 Aggregation and Composition as Relationships Between Classes 15
1.6.3 Representing Attributes 16
1.6.4 Representing Operations 17
I CREATIONAL PATTERNS 19
2 Abstract Factory 21
2.1 The Concept of a Factory in Software 21
2.2 Intent and Applicability 22
2.3 Introduction to the Abstract Factory Pattern 22
2.4 The Abstract Factory Pattern in Real-World Applications 23
2.5 Harry Potter Story Used to Illustrate the Abstract Factory Pattern 23
2.6 A Top Level View of the Pattern Demonstration 25
2.7 The Abstract Class Factory 27
2.8 The Helper Class FactoryStore 27
2.9 The Abstract Class Enchanted 30
2.10 The Concrete Classes for Magical Objects 31
2.11 The Concrete Factory Classes 32
2.12 The Client Class Diagon AlleyRetailer 34
2.13 Playing with the Code 36
3 Builder 38
3.1 Building Complex Objects 38
3.2 Intent and Applicability 39
3.3 Introduction to the Builder Pattern 39
3.4 The Builder Pattern in Real-World Applications 41
3.5 Harry Potter Story Used to Illustrate the Builder Pattern 42
3.6 A Top-Level View of the Pattern Demonstration 43
3.7 The Abstract Class PotionMaker 45
3.8 The Concrete Extensions of PotionMaker 46
3.9 The Director Class 52
3.10 The Potion Class 54
3.11 The Ingredient Class 55
3.12 The PotionMakingFeasibilityViolation Class 55
3.13 The Client Class 55
3.14 Playing with the Code 56
4 Factory Method 59
4.1 Revisiting the Concept of a Factory in Software 59
4.2 Intent and Applicability 60
4.3 Introduction to the Factory Method Pattern 60
4.4 The Factory Method Pattern in Real-World Applications 61
4.5 Harry Potter Story Used to Illustrate the Factory Method Pattern 62
4.6 A Top Level View of the Pattern Demonstration 63
4.7 The Enchanted Class Hierarchy 65
4.8 The ArtifactFactory Class Hierarchy and the Factory Methods Contained Therein 68
4.9 The Client Class 70
4.10 Playing with the Code 71
5 Prototype 73
5.1 Why Not Make New Objects by Copying Old Objects? 73
5.2 Intent and Applicability 74
5.3 Introduction to the Prototype Pattern 74
5.4 The Prototype Pattern in Real-World Applications 77
5.5 Harry Potter Story Used to Illustrate The Prototype Pattern 78
5.6 A Top Level View of the Pattern Demonstration 79
5.7 The Dragon Class 81
5.8 The PrototypeManagerAndDuplicator Class 84
5.9 The DragonAficionado Class 87
5.10 The UnknownDragonException Class 88
5.11 Playing with the Code 88
6 Singleton 90
6.1 Singular Objects 90
6.2 Intent and Applicability 90
6.3 Introduction to the Singleton Pattern 91
6.4 The Singleton Pattern in Real-World Applications 91
6.5 Harry Potter Story Used to Illustrate the Singleton Pattern 92
6.6 A Top Level View of the Pattern Demonstration 92
6.7 The MinisterForMagic Class 93
6.8 The TestSingleton Class 94
6.9 Variations on the Singleton Pattern 95
6.10 Playing with the Code 97
II STRUCTURAL PATTERNS 99
7 Adapter 101
7.1 Getting Things to Work Together 101
7.2 I