Designing with Objects : Object-Oriented Design Patterns Explained with Stories from Harry Potter
[BOOK DESCRIPTION]
With an innovative approach to a vital topic in software development, author Avinash Kak demonstrates the key concepts of object-oriented design. Designing with Objects explains the intricacies of design patterns, like Abstract Factory, Builder, Singleton, Adaptor, Bridge, and others, but it does so with flair. Each chapter brims with examples from Harry Potter stories to comprise a thorough, digestible reference for engineering students and programmers.
[TABLE OF CONTENTS]
Preface xiv
Acknowledgments xix
1 Why Learn Design Patterns and Why Do So 1 (18)
with Help from Harry Potter?
1.1 The OO Design Patterns "Bible" by GoF 2 (2)
1.2 But What Has Harry Potter Got to Do 4 (2)
with OO Design Patterns?
1.3 Is Familiarity with Harry Potter a 6 (1)
Requirement for Understanding This Book?
1.4 How the Pattern Explanations are 7 (1)
Organized
1.5 The Terminology of Object-Oriented 7 (5)
Programming
1.6 The UML Notation Used in the Class 12 (9)
Diagrams
1.6.1 Association as a Relationship 14 (1)
Between Classes
1.6.2 Aggregation and Composition as 15 (1)
Relationships Between Classes
1.6.3 Representing Attributes 16 (1)
1.6.4 Representing Operations 17 (2)
I Creational Patterns 19 (80)
2 Abstract Factory 21 (17)
2.1 The Concept of a Factory in Software 21 (1)
2.2 Intent and Applicability 22 (1)
2.3 Introduction to the Abstract Factory 22 (1)
Pattern
2.4 The Abstract Factory Pattern in 23 (1)
Real-World Applications
2.5 Harry Potter Story Used to Illustrate 23 (2)
the Abstract Factory Pattern
2.6 A Top Level View of the Pattern 25 (2)
Demonstration
2.7 The Abstract Class Factory 27 (1)
2.8 The Helper Class FactoryStore 27 (3)
2.9 The Abstract Class Enchanted 30 (1)
2.10 The Concrete Classes for Magical 31 (1)
Objects
2.11 The Concrete Factory Classes 32 (2)
2.12 The Client Class Diagon AlleyRetailer 34 (2)
2.13 Playing with the Code 36 (2)
3 Builder 38 (21)
3.1 Building Complex Objects 38 (1)
3.2 Intent and Applicability 39 (1)
3.3 Introduction to the Builder Pattern 39 (2)
3.4 The Builder Pattern in Real-World 41 (1)
Applications
3.5 Harry Potter Story Used to Illustrate 42 (1)
the Builder Pattern
3.6 A Top-Level View of the Pattern 43 (2)
Demonstration
3.7 The Abstract Class PotionMaker 45 (1)
3.8 The Concrete Extensions of PotionMaker 46 (6)
3.9 The Director Class 52 (2)
3.10 The Potion Class 54 (1)
3.11 The Ingredient Class 55 (1)
3.12 The PotionMakingFeasibilityViolation 55 (1)
Class
3.13 The Client Class 55 (1)
3.14 Playing with the Code 56 (3)
4 Factory Method 59 (14)
4.1 Revisiting the Concept of a Factory in 59 (1)
Software
4.2 Intent and Applicability 60 (1)
4.3 Introduction to the Factory Method 60 (1)
Pattern
4.4 The Factory Method Pattern in 61 (1)
Real-World Applications
4.5 Harry Potter Story Used to Illustrate 62 (1)
the Factory Method Pattern
4.6 A Top Level View of the Pattern 63 (2)
Demonstration
4.7 The Enchanted Class Hierarchy 65 (3)
4.8 The ArtifactFactory Class Hierarchy and 68 (2)
the Factory Methods Contained Therein
4.9 The Client Class 70 (1)
4.10 Playing with the Code 71 (2)
5 Prototype 73 (17)
5.1 Why Not Make New Objects by Copying Old 73 (1)
Objects?
5.2 Intent and Applicability 74 (1)
5.3 Introduction to the Prototype Pattern 74 (3)
5.4 The Prototype Pattern in Real-World 77 (1)
Applications
5.5 Harry Potter Story Used to Illustrate 78 (1)
The Prototype Pattern
5.6 A Top Level View of the Pattern 79 (2)
Demonstration
5.7 The Dragon Class 81 (3)
5.8 The PrototypeManagerAndDuplicator Class 84 (3)
5.9 The DragonAficionado Class 87 (1)
5.10 The UnknownDragonException Class 88 (1)
5.11 Playing with the Code 88 (2)
6 Singleton 90 (9)
6.1 Singular Objects 90 (1)
6.2 Intent and Applicability 90 (1)
6.3 Introduction to the Singleton Pattern 91 (1)
6.4 The Singleton Pattern in Real-World 91 (1)
Applications
6.5 Harry Potter Story Used to Illustrate 92 (1)
the Singleton Pattern
6.6 A Top Level View of the Pattern 92 (1)
Demonstration
6.7 The MinisterForMagic Class 93 (1)
6.8 The TestSingleton Class 94 (1)
6.9 Variations on the Singleton Pattern 95 (2)
6.10 Playing with the Code 97 (2)
II Structural Patterns 99 (150)
7 Adapter 101(21)
7.1 Getting Things to Work Together 101(1)
7.2 Intent and Applicability 102(1)
7.3 Introduction to the Adapter Pattern 102(1)
7.4 The Adapter Pattern in Real-World 103(1)
Applications
7.5 Harry Potter Story Used to Illustrate 104(1)
the Adapter Pattern
7.6 A Top Level View of the Pattern 104(2)
Demonstration
7.7 The Target Interface: TeachingDADA 106(1)
7.8 The TeacherForDADA Class 107(1)
7.9 The AdapterForSafeTeaching Class 108(2)
7.10 The Client Class SchoolOfMagic 110(1)
7.11 Object Adapter 111(2)
7.12 Pluggable Adapter 113(6)
7.13 Playing with the Code 119(3)
8 Bridge 122(20)
8.1 Concepts and Their Implementation 122(1)
8.2 Intent and Applicability 123(1)
8.3 Introduction to the Bridge Pattern 123(3)
8.4 The Bridge Pattern in Real-World 126(1)
Applications
8.5 Harry Potter Story Used to Illustrate 127(3)
the Bridge Pattern
8.6 A Top Level View of the Pattern 130(1)
Demonstration
8.7 The Humanoid Class 130(2)
8.8 The Dementor, Goblin, and HouseElf 132(2)
Classes
8.9 The Humanoid_Imp Class 134(3)
8.10 Implementation Classes for the 137(2)
Dementor, Goblin, and HouseElf Classes
8.11 The Client Class MinistryOfMagic 139(1)
8.12 Playing with the Code 140(2)
9 Composite 142(19)
9.1 Relationships That Loop Back 142(1)
9.2 Intent and Applicability 143(1)
9.3 Introduction to the Composite Pattern 144(1)
9.4 The Composite Pattern in Real-World 145(1)
Applications
9.5 Harry Potter Story Used to Illustrate 146(1)
the Composite Pattern
9.6 A Top Level View of the Pattern 147(1)
Demonstration
9.7 The WizardTraits Interface 148(1)
9.8 The Wizard Class 149(3)
9.9 The Auror Class 152(1)
9.10 The Obliviator Class 153(2)
9.11 The DepartmentHead Class 155(1)
9.12 The Minister for Magic Class 156(2)
9.13 The Client Class Test 158(1)
9.14 Playing with the Code 159(2)
10 Decorator 161(14)
10.1 Onion as a Metaphor 161(1)
10.2 Intent and Applicability 162(1)
10.3 Introduction to the Decorator Pattern 162(2)
10.4 The Decorator Pattern in Real-World 164(1)
Applications
10.5 Harry Potter Story Used to Illustrate 165(3)
the Decorator Pattern
10.6 A Top Level View of the Pattern 168(2)
Demonstration
10.7 The CoreMessageDeliveryClass Class 170(1)
10.8 The Decorator Classes 170(2)
10.9 The Client Class Test 172(1)
10.10 Playing with the Code 173(2)
11 Facade 175(37)
11.1 Hiding Complexity 175(1)
11.2 Intent and Applicability 175(1)
11.3 Introduction to the Facade Pattern 176(1)
11.4 The Facade Pattern in Real-World 177(1)
Applications
11.5 Harry Potter Story Used to Illustrate 177(2)
the Facade Pattern
11.6 A Top Level View of the Pattern 179(2)
Demonstration
11.7 The Abstract Root Class Facade 181(2)
11.8 The Network Class 183(10)
11.9 The Node, Link, and Path Classes 193(5)
11.10 The Three Concrete Facade Classes 198(5)
11.11 Testing the Demonstration Code 203(4)
11.12 Playing with the Code 207(5)
12 Flyweight 212(18)
12.1 The Idea of Customized Duplications 212(1)
12.2 Intent and Applicability 213(1)
12.3 Introduction to the Flyweight Pattern 213(1)
12.4 The Flyweight Pattern in Real-World 214(1)
Applications
12.5 Harry Potter Story Used to Illustrate 214(1)
the Flyweight Pattern
12.6 A Top Level View of the Pattern 215(3)
Demonstration
12.7 The HeadMasterPortrait Class 218(1)
12.8 The FlyweightlmageStore Class 218(1)
12.9 The ImageManager Class 219(6)
12.10 The PortraitBorderChoices Class 225(1)
12.11 The ImageNotAvailableException Class 226(1)
12.12 The PortraitMakerAssignment Class 226(2)
12.13 Playing with the Code 228(1)
12.14 Acknowledgment 229(1)
13 Proxy 230(19)
13.1 Is It Always Necessary to Have the 230(1)
Real Thing?
13.2 Intent and Applicability 230(1)
13.3 Introduction to the Proxy Pattern 231(1)
13.4 The Proxy Pattern in Real-World 232(1)
Applications
13.5 Harry Potter Story Used to Illustrate 233(2)
the Proxy Pattern
13.6 A Top Level View of the Pattern 235(1)
Demonstration
13.7 The Abstract Class Wizard 235(2)
13.8 The DarkWizardTraits Interface 237(1)
13.9 The DarkWizard Class 238(4)
13.10 The DarkLord Class 242(3)
13.11 The ClientClass Class 245(1)
13.12 Playing with the Code 246(3)
III Behavioral Patterns 249(224)
14 Chain of Responsibility 253(19)
14.1 Passing the Buck 253(1)
14.2 Intent and Applicability 254(1)
14.3 Introduction to the Chain of 254(1)
Responsibility Pattern
14.4 The Chain of Responsibility Pattern in 255(1)
Real-World Applications
14.5 Harry Potter Story Used to Illustrate 256(2)
the Chain of Responsibility Pattern
14.6 A Top Level View of the Pattern 258(2)
Demonstration
14.7 The Interface Class Violations 260(1)
14.8 The Abstract Class Adjudicator 261(2)
14.9 The Player Class 263(2)
14.10 The Classes with the Authority to 265(3)
Resolve Violations
14.11 Testing the Code 268(1)
14.12 Playing with the Code 269(3)
15 Command 272(18)
15.1 Actions Versus the Actors 272(1)
15.2 Intent and Applicability 273(1)
15.3 Introduction to the Command Pattern 274(1)
15.4 The Command Pattern in Real-World 274(2)
Applications
15.5 Harry Potter Story Used to Illustrate 276(1)
the Command Pattern
15.6 A Top Level View of the Pattern 277(2)
Demonstration
15.7 The Command Interface 279(1)
15.8 The MyPlaces Interface 279(1)
15.9 The ProtectHarryPotter Class 279(3)
15.10 The Wizard Class 282(2)
15.11 The Squib Class 284(1)
15.12 The Invoker Class 285(1)
15.13 The 286(1)
UnableToProtectHarryPotterException Class
15.14 The Client Class 286(2)
15.15 Playing with the Code 288(2)
16 Interpreter 290(31)
16.1 Parsing versus Interpretation 290(2)
16.2 Intent and Applicability 292(1)
16.3 Introduction to the Interpreter Pattern 292(1)
16.4 The Interpreter Pattern in Real-World 293(1)
Applications
16.5 Harry Potter Story Used to Illustrate 294(2)
the Interpreter Pattern
16.6 A Parser Front-End for the Interpreter 296(8)
Pattern
16.7 A Top Level View of the Pattern 304(3)
Demonstration
16.8 The Driver Class 307(3)
16.9 The Interpreter_Sentence Class 310(2)
16.10 The Worker Classes for Interpretation 312(3)
16.11 The Utility Class ShowSyntaxTree 315(1)
16.12 Playing with the Code 316(5)
17 Iterator 321(32)
17.1 Storing Object Collections and 321(2)
Interacting with Them
17.2 Intent and Applicability 323(1)
17.3 Introduction to the Iterator Pattern 323(1)
17.4 The Iterator Pattern in Real-World 324(1)
Applications
17.5 Harry Potter Story Used to Illustrate 325(1)
the Iterator Pattern
17.6 A Top Level View of the Pattern 326(2)
Demonstration
17.7 A Utility Interface for Demonstrating 328(2)
the Iterator Pattern
17.8 The Iterator Interface 330(1)
17.9 The Fresher Class 330(4)
17.10 The SortingHat Class 334(10)
17.11 The MagicCollection Interface 344(1)
17.12 The MagicList and MagicSet Classes 344(5)
17.13 The Class Range 349(1)
17.14 Playing with the Code 349(3)
17.15 Credits 352(1)
18 Mediator 353(18)
18.1 The Role of Mediation in Collaborative 353(1)
Problem Solving
18.2 Intent and Applicability 354(1)
18.3 Introduction to the Mediator Pattern 354(1)
18.4 The Mediator Pattern in Real-World 355(2)
Applications
18.5 Harry Potter Story Used to Illustrate 357(1)
the Mediator Pattern
18.6 A Top Level View of the Pattern357(2)
Demonstration
18.7 The Abstract Class Mediator 359(1)
18.8 The Interface TrialElements 360(1)
18.9 The MinistryOfMagicTrialMediator Class 361(5)
18.10 The Witness Class 366(1)
18.11 The Trial Interface 367(1)
18.12 The Harry PotterTrial Class 367(2)
18.13 Playing with the Code 369(2)
19 Memento 371(15)
19.1 Recalling the Past 371(1)
19.2 Intent and Applicability 372(1)
19.3 Introduction to the Memento Pattern 372(2)
19.4 The Memento Pattern in Real-World 374(1)
Applications
19.5 Harry Potter Story Used to Illustrate 374(3)
the Memento Pattern
19.6 A Top Level View of the Pattern 377(1)
Demonstration
19.7 The HogwartsHappening Class and The 378(2)
Inner Memento Class
19.8 The Client Class 380(4)
19.9 Playing with the Code 384(2)
20 Observer 386(19)
20.1 Subscription-Based Broadcasting 386(1)
20.2 Intent and Applicability 387(1)
20.3 Introduction to the Observer Pattern 387(1)
20.4 The Observer Pattern in Real-World 388(1)
Applications
20.5 Harry Potter Story Used to Illustrate 389(2)
the Observer Pattern
20.6 A Top Level View of the Pattern 391(1)
Demonstration
20.7 The Observer Interface 391(2)
20.8 The Observable Interface 393(1)
20.9 The DarkLord Class 393(3)
20.10 The DeathEater Class 396(3)
20.11 The GodProcess Class 399(2)
20.12 Playing with the Code 401(4)
21 State 405(16)
21.1 Contextual Dependence of Behaviors 405(1)
21.2 Intent and Applicability 406(1)
21.3 Introduction to the State Pattern 406(1)
21.4 The State Pattern in Real-World 406(1)
Applications
21.5 Harry Potter Story Used to Illustrate 407(1)
the State Pattern
21.6 A Top Level View of the Pattern 408(2)
Demonstration
21.7 The DADA_State Interface 410(1)
21.8 The Year-by-Year Implementation 411(6)
Classes for the State
21.9 The TeachingDADA Class 417(1)
21.10 The Hogwarts Class 418(1)
21.11 Playing with the Code 419(2)
22 Strategy 421(16)
22.1 Strategies in the Pursuit of Goals 421(1)
22.2 Intent and Applicability 422(1)
22.3 Introduction to the Strategy Pattern 422(1)
22.4 The Strategy Pattern in Real-World 423(1)
Applications
22.5 Harry Potter Story Used to Illustrate 424(1)
the Strategy Pattern
22.6 A Top Level View of the Pattern 425(3)
Demonstration
22.7 The Abstract Root Class for 428(1)
Strategies: StrategyAbstractRoot
22.8 The Concrete Strategy Classes 429(3)
22.9 The Champion Class 432(2)
22.10 The SecondTaskManager Class 434(2)
22.11 Playing with the Code 436(1)
23 Template Method 437(16)
23.1 Customizable Recipes 437(1)
23.2 Intent and Applicability 438(1)
23.3 Introduction to the Template Method 438(2)
Pattern
23.4 The Template Method Pattern in 440(1)
Real-World Applications
23.5 Harry Potter Story Used to Illustrate 441(1)
the Template Method Pattern
23.6 A Top Level View of the Pattern 442(2)
Demonstration
23.7 The Abstract Root of Narrative 444(1)
Generation Classes
23.8 Concrete Classes for Narrative 445(4)
Generation
23.9 The Executable Class 449(1)
23.10 Playing with the Code 450(3)
24 Visitor 453(20)
24.1 Hooks, Good and Evil 453(1)
24.2 Intent and Applicability 454(1)
24.3 Introduction to the Visitor Pattern 454(3)
24.4 The Visitor Pattern in Real-World 457(1)
Applications
24.5 Harry Potter Story Used to Illustrate 457(2)
the Visitor Pattern
24.6 A Top Level View of the Pattern 459(1)
Demonstration
24.7 The Visitor Interface 460(2)
24.8 Two Concrete Implementations of the 462(1)
Visitor Interface
24.9 A Re-Implementation of the Wizard 463(6)
Hierarchy of the Composite Pattern
24.10 The Executable Class Client 469(1)
24.11 Playing with the Code 470(3)
References 473(1)
Index 474