Head First design patterns: Includes index
0596007124, 9780596007126
You're not alone.
At any given moment, somewhere in the world someone struggles with the same software design prob
264
47
43MB
English
Pages xxxvi, 638 Seiten Seiten
[619]
Year 2004
Report DMCA / Copyright
DOWNLOAD PDF FILE
Table of contents :
Welcome to Design Patterns......Page 3
It started with a simple SimUDuck app......Page 4
But now we need the ducks to FLY......Page 5
But something went horribly wrong.........Page 6
Sharpen your pencil......Page 7
How about an interface?......Page 8
What would you do if you were Joe?......Page 9
Sharpen your pencil......Page 10
Zeroing in on the problem.........Page 11
Separating what changes from what stays the same......Page 12
Designing the Duck Behaviors......Page 13
Implementing the Duck Behaviors......Page 15
Sharpen your pencil......Page 16
Integrating the Duck Behavior......Page 17
More Integration.........Page 18
Testing the Duck code......Page 20
Setting behavior dynamically......Page 22
The Big Picture on encapsulated behaviors......Page 24
HAS-A can be better than IS-A......Page 25
Speaking of Design Patterns.........Page 26
Design Puzzle......Page 27
Overheard at the local diner.........Page 28
Overheard in the next cubicle.........Page 29
The power of a shared pattern vocabulary......Page 30
There are no Dumb Questions......Page 31
Skeptical Developer-Friendly Patterns Guru......Page 32
Tools for your Design Toolbox......Page 34
Design Puzzle Solution......Page 36
Solutions......Page 37
Keeping your Objects in the know......Page 39
The Weather Monitoring application overview......Page 41
Unpacking the WeatherData class......Page 42
What do we know so far ?......Page 43
Sharpen your pencil......Page 44
What's wrong with our implementation?......Page 45
Meet the Observer Pattern......Page 46
Publishers + Subscribers = Observer Pattern......Page 47
A day in the life of the Observer Pattern......Page 48
Five minute drama: a subject for observation......Page 50
Two weeks later.........Page 52
The Observer Pattern defined......Page 53
The Observer Pattern defined: the class diagram......Page 54
The power of Loose Coupling......Page 55
Sharpen your pencil......Page 56
Cubicle conversation......Page 57
Designing the Weather Station......Page 58
Implementing the Weather Station......Page 59
Implementing the Subject interface in WeatherData......Page 60
There are no Dumb Questions......Page 61
Power up the Weather Station......Page 62
Sharpen your pencil......Page 63
Using Java's built-in Observer Pattern......Page 66
How Java's built-in Observer Pattern works......Page 67
Reworking the Weather Station with the built-in support......Page 69
Now, let's rework the CurrentConditionsDisplay......Page 70
Exercise: Code Magnets......Page 71
Running the new code......Page 72
The dark side of java.util.Observable......Page 73
Other places you'll find the Observer Pattern in the JDK......Page 74
And the code.........Page 75
Tools for your Design Toolbox......Page 76
Exercise: Design Principle Challenge......Page 77
Exercise solutions: Design Principle Challenge......Page 79
Code Magnets: Exercise solutions......Page 80
Decorating Objects......Page 81
Welcome to Starbuzz Coffee......Page 82
Master and Student......Page 87
The Open-Closed Principle......Page 88
Meet the Decorator Pattern......Page 90
Constructing a drink order with Decorators......Page 91
The Decorator Pattern defined......Page 93
Decorating our Beverages......Page 94
Cubicle Conversation......Page 95
New barista training......Page 96
Writing the Starbuzz code......Page 97
Coding beverages......Page 98
Coding condiments......Page 99
Ser ving some coffees......Page 100
Real World Decorators: Java I/O......Page 102
Decorating the java.io classes......Page 103
Writing your own Java I/O Decorator......Page 104
Test out your new Java I/O Decorator......Page 105
Tools for your Design Toolbox......Page 107
Pattern Exposed......Page 106
Exercise solutions......Page 108
Baking with OO Goodness......Page 111
Brain Power......Page 113
Identifying the aspects that vary......Page 114
But the pressure is on to add more pizza types......Page 115
Encapsulating object creation......Page 116
There are no Dumb Questions......Page 117
Reworking the PizzaStore class......Page 118
The Simple Factory defined......Page 119
Franchising the pizza store......Page 120
A framework for the pizza store......Page 122
Allowing the subclasses to decide......Page 123
Let's make a PizzaStore......Page 125
Declaring a factory method......Page 127
Let's see how it works: ordering pizzas with the pizza factory method......Page 128
Let's check out how these pizzas are really made to order... Behind the Scenes......Page 129
We're just missing one thing: PIZZA!......Page 130
Now we just need some concrete subclasses... how about defining New York and Chicago style cheese pizzas?......Page 131
It's finally time to meet the Factory Method Pattern......Page 133
Another perspective: parallel class hierarchies......Page 134
Design Puzzle......Page 135
Factory Method Pattern defined......Page 136
There are no Dumb Questions......Page 137
A very dependent PizzaStore......Page 139
Looking at object dependencies......Page 140
The Dependency Inversion Principle......Page 141
Applying the Principle......Page 142
Inverting your thinking.........Page 144
A few guidelines to help you follow the Principle.........Page 145
Meanwhile, back at the PizzaStore.........Page 146
Families of ingredients.........Page 147
Building the ingredient factories......Page 148
Building the New York ingredient factory......Page 149
Sharpen your pencil......Page 150
Reworking the pizzas.........Page 151
Reworking the pizzas, continued.........Page 152
Code Up Close......Page 153
Revisiting our pizza stores......Page 154
What have we done?......Page 155
More pizza for Ethan and Joel.........Page 156
Abstract Factory Pattern defined......Page 158
Patterns Exposed......Page 160
Factory Method and Abstract Factory compared......Page 162
Tools for your Design Toolbox......Page 164
Sharpen your pencil......Page 166
Design Puzzle Solution......Page 167
Sharpen your pencil......Page 168
Sharpen your pencil......Page 169
Puzzle Solution......Page 170
One of a Kind Objects......Page 172
The Little Singleton: A small Socratic exercise in the style of The Little Lisper......Page 174
Dissecting the classic Singleton Pattern implementation......Page 176
Patterns Exposed......Page 177
The Chocolate Factory......Page 178
Sharpen your pencil......Page 179
Singleton Pattern defined......Page 180
Hershey, PA: Houston, we have a problem.........Page 181
BE the JVM......Page 182
Dealing with multithreading......Page 183
Can we improve multithreading?......Page 184
Congratulations!......Page 186
there are no Dumb Questions......Page 187
Tools for your Design Toolbox......Page 189
Exercise solutions......Page 191
Exercise Solutions......Page 192
Exercise solutions......Page 193
Encapsulating Invocation......Page 195
Free hardware! Let's check out the Remote Control.........Page 197
Taking a look at the vendor classes......Page 198
Cubicle Conversation......Page 199
Meanwhile, back at the Diner..., or, A brief introduction to the Command Pattern......Page 201
Let's study the interaction in a little more detail.........Page 202
The Objectville Diner roles and responsibilities......Page 203
From the Diner to the Command Pattern......Page 205
Our first command object......Page 207
Creating a simple test to use the Remote Control......Page 208
Sharpen your pencil......Page 209
The Command Pattern defined......Page 210
BRAIN POWER......Page 211
Assigning Commands to slots......Page 213
Implementing the Remote Control......Page 214
Implementing the Commands......Page 215
Putting the Remote Control Through Its Paces......Page 216
Now, Let's Check Out the Execution of Our Remote Control Test.........Page 217
Time to Write That Documentation.........Page 219
What are we Doing?......Page 220
Time to QA That Undo Button!......Page 223
Using State to Implement Undo......Page 224
Adding Undo to the Ceiling Fan Commands......Page 225
Get Ready to Test the Ceiling Fan......Page 226
Testing the Ceiling Fan.........Page 227
Every Remote Needs a Party Mode!......Page 228
Using a Macro Command......Page 229
There are no Dumb Questions......Page 231
More Uses of the Command Pattern: Queuing Requests......Page 232
More Uses of the Command Pattern: Logging Requests......Page 233
Tools for your Design Toolbox......Page 234
Exercise Solutions......Page 236
Exercise Solutions......Page 237
Being Adaptive......Page 239
Adapters all around us......Page 240
Object oriented adapters......Page 241
If it walks like a duck and quacks like a duck, then it must might be a duck turkey wrapped with a duck adapter.........Page 242
Test drive the adapter......Page 244
The Adapter Pattern explained......Page 245
There are no Dumb Questions......Page 246
Adapter Pattern defined......Page 247
Object and class adapters......Page 248
Duck Magnets......Page 249
Duck Magnets Answer......Page 250
Fireside Chats......Page 251
Real world adapters......Page 252
Adapting an Enumeration to an Iterator......Page 253
Fireside Chats......Page 256
And now for something different.........Page 258
Home Sweet Home Theater......Page 259
Watching a movie (the hard way)......Page 260
Lights, Camera, Facade!......Page 262
There are no Dumb Questions......Page 264
Constructing your home theater facade......Page 265
Implementing the simplified interface......Page 266
Time to watch a movie (the easy way)......Page 267
Facade Pattern defined......Page 268
The Principle of Least Knowledge......Page 269
How NOT to Win Friends and Influence Objects......Page 270
there are no Dumb Questions......Page 271
The Facade and the Principle of Least Knowledge......Page 273
Tools for your Design Toolbox......Page 274
Exercise solutions......Page 276
Exercise solutions......Page 277
Exercise solutions......Page 278
Encapsulating Algorithms......Page 280
It's time for some more caffeine......Page 281
Whipping up some coffee and tea classes (in Java)......Page 282
Sir, may I abstract your Coffee, Tea?......Page 285
Taking the design further.........Page 286
Abstracting prepareRecipe()......Page 287
What have we done?......Page 290
Meet the Template Method......Page 291
Let's make some tea...: Behind the Scenes......Page 292
What did the Template Method get us?......Page 293
Template Method Pattern defined......Page 294
Hooked on Template Method.........Page 297
Using the hook......Page 298
Let's run the TestDrive......Page 299
there are no Dumb Questions......Page 300
The Hollywood Principle......Page 301
The Hollywood Principle and Template Method......Page 302
there are no Dumb Questions......Page 303
Template Methods in the Wild......Page 304
Sorting with Template Method......Page 305
What is compareTo()?......Page 306
Comparing Ducks and Ducks......Page 307
Let's sort some Ducks......Page 308
The making of the sorting duck machine......Page 309
there are no Dumb Questions......Page 310
Swingin' with Frames......Page 311
Applets......Page 312
Fireside Charts......Page 313
Tools for your Design Toolbox......Page 316
Exercise solutions......Page 317
Exercise solutions......Page 318
Well-Managed Collections......Page 321
Breaking News: Objectville Diner Merge and Objectville Pancake House......Page 322
Check out the Menu Items......Page 323
Lou and Mel's Menu implementations......Page 324
What's the problem with having two different menu representations?......Page 326
What now?......Page 328
Can we encapsulate the iteration?......Page 329
Meet the Iterator Pattern......Page 331
Adding an Iterator to DinerMenu......Page 332
Exercise......Page 333
Fixing up the Waitress code......Page 334
Testing our code......Page 335
What have we done so far?......Page 336
What we have so far.........Page 337
There are no Dumb Questions......Page 338
Cleaning things up with java.util.Iterator......Page 339
We are almost there.........Page 340
What does this get us?......Page 341
Iterator Pattern defined......Page 342
There are no Dumb Questions......Page 344
Single Responsibility......Page 345
BRAIN2 POWER......Page 346
Sharpen your pencil......Page 348
Code Up Close......Page 349
Adding the Café Menu to the Waitress......Page 350
Breakfast, lunch AND dinner......Page 351
We decoupled the Waitress..........Page 352
But there's more!......Page 353
Iterators and Collections......Page 354
Iterators and Collections in Java 5......Page 355
Code Magnets......Page 356
Is the Waitress ready for prime time?......Page 357
Just when we thought it was safe.........Page 359
What do we need?......Page 360
The Composite Pattern defined......Page 362
Designing Menus with Composite......Page 365
Implementing the Menu Component......Page 366
Implementing the Menu Item......Page 367
Implementing the Composite Menu......Page 368
Getting ready for a test drive.........Page 370
Now for the test drive.........Page 371
Getting ready for a test drive.........Page 372
Flashback to Iterator......Page 374
The Composite Iterator......Page 375
The Null Iterator......Page 378
Give me the vegetarian menu......Page 379
The magic of Iterator & Composite together.........Page 380
Patterns Exposed......Page 382
WHO DOES WHAT?......Page 385
Tools for your Design Toolbox......Page 386
Exercise solutions......Page 387
Code Magnets Solution......Page 388
WHO DOES WHAT?......Page 389
Exercise Solution......Page 390
The State of Things......Page 392
Java Breakers......Page 393
Cubicle Conversation......Page 394
State machines 101......Page 395
Writing the code......Page 397
In-house testing......Page 399
You knew it was coming... a change request!......Page 401
Design Puzzle......Page 402
The messy STATE of things.........Page 403
The new design......Page 405
Defining the State interfaces and classes......Page 406
Implementing our State classes......Page 408
Reworking the Gumball Machine......Page 409
Implementing more states......Page 411
Let's take a look at what we've done so far.........Page 414
Sharpen your pencil......Page 416
The State Pattern defined......Page 417
there are no Dumb Questions......Page 419
We still need to finish the Gumball 1 in 10 game......Page 420
Finishing the game......Page 421
Demo for the CEO of Mighty Gumball, Inc.......Page 422
there are no Dumb Questions......Page 423
Sanity check.........Page 424
We almost forgot!......Page 427
Sharpen your pencil......Page 428
Tools for your Design Toolbox......Page 430
Exercise solutions......Page 431
Exercise solutions......Page 432
Controlling Object Access......Page 437
Coding the Monitor......Page 439
Testing the Monitor......Page 440
The role of the 'remote proxy'......Page 442
Adding a remote proxy to the Gumball Machine monitoring code......Page 444
Remote methods 101......Page 445
How the method call happens......Page 446
Java RMI, the Big Picture......Page 448
Making the Remote service......Page 449
Step one: make a Remote interface......Page 450
Step two: make a Remote implementation......Page 451
Step five: start the service......Page 452
How does the client get the stub object?......Page 454
Watch it......Page 457
Back to our GumballMachine remote proxy......Page 458
Getting the GumballMachine ready to be a remote service......Page 459
Registering with the RMI registry.........Page 461
Now for the GumballMonitor client.........Page 462
Writing the Monitor test drive......Page 463
Another demo for the CEO of Mighty Gumball.........Page 464
And now let's put the monitor in the hands of the CEO. Hopefully this time he'll love it:......Page 465
Behind the Scenes......Page 466
The Proxy Pattern defined......Page 468
Get ready for Virtual Proxy......Page 470
Displaying CD covers......Page 471
Designing the CD cover Virtual Proxy......Page 472
Writing the Image Proxy......Page 473
Design Puzzle......Page 476
Testing the CD Cover Viewer......Page 477
What did we do?: Behin the scenes......Page 478
there are no Dumb Questions......Page 479
Fireside Charts......Page 480
Using the Java API's Proxy to create a protection proxy......Page 482
Matchmaking in Objectville......Page 483
The PersonBean implementation......Page 484
Five minute drama: protecting subjects......Page 486
Big Picture: creating a Dynamic Proxy for the PersonBean......Page 487
Step one: creating Invocation Handlers......Page 488
Creating Invocation Handlers continued.........Page 489
Exercise......Page 490
Sharpen your pencil......Page 491
Testing the matchmaking service......Page 492
Running the code.........Page 493
there are no Dumb Questions......Page 494
WHO DOES WHAT......Page 495
The Proxy Zoo......Page 496
Tools for your Design Toolbox......Page 499
Exercise solutions......Page 500
Exercise solutions......Page 501
Ready-bake Code: The code for the CD Cover Viewer......Page 502
Ready-bake Code: The code for the CD Cover Viewer, continued.........Page 504
Patterns of Patterns......Page 507
Working together......Page 508
Duck reunion......Page 509
There are no Dumb Questions......Page 530
What did we do?......Page 531
A bird's duck's eye view: the class diagram......Page 532
The King of Compound Patterns......Page 534
Meet the Model-View-Controller......Page 537
A closer look.........Page 538
There are no Dumb Questions......Page 539
Looking at MVC through patterns-colored glasses......Page 540
Meet the Java DJ View......Page 542
Putting the pieces together......Page 544
Building the pieces......Page 545
Now let's have a look at the concrete BeatModel class:......Page 546
BRAIN POWER......Page 547
Implementing the View......Page 548
Implementing the View, continued.........Page 549
Now for the Controller......Page 550
And here's the implementation of the controller:......Page 551
And now for a test run.........Page 552
Exploring Strategy......Page 553
Adapting the Model......Page 554
Now we're ready for a HeartController......Page 555
And now for a test run.........Page 556
MVC and the Web......Page 557
Model 2 is more than just a clean design.......Page 558
Model 2: DJ'ing from a cell phone......Page 559
Now we need a view.........Page 562
Putting Model 2 to the test.........Page 563
Observer......Page 565
Strategy......Page 566
There are no Dumb Questions......Page 567
Tools for your Design Toolbox......Page 568
Exercise solutions......Page 569
Ready-bake Code......Page 572
Ready-bake Code: The View......Page 576
The Controller......Page 579
The Heart Model......Page 581
The Heart Adapter......Page 583
The Controller......Page 584
Patterns in the Real World......Page 586
Design Pattern defined......Page 588
Looking more closely at the Design Pattern definition......Page 590
Geek Bits......Page 591
there are no Dumb Questions......Page 595
So you wanna be a Design Patterns writer......Page 596
Organizing Design Patterns......Page 598
Solution: Pattern Categories......Page 599
there are no Dumb Questions......Page 600
Thinking in Patterns......Page 603
Your Mind on Patterns......Page 606
Don't forget the power of the shared vocabulary......Page 608
Cruisin' Object ville with the Gang of Four......Page 610
Your journey has just begun.........Page 611
The Patterns Zoo......Page 613
Annihilating evil with Anti-Patterns......Page 615
Tools for your Design Toolbox......Page 617
Leaving Objectville.........Page 618
Exercise solutions......Page 619
Recommend Papers
File loading please wait...
Citation preview
www.it-ebooks.info
Chapter 1. Welcome to Design Patterns
Table of Contents Chapter 1. Welcome to Design Patterns....................................................... 1 Section 1.1. It started with a simple SimUDuck app....................................................................................................................... 2 Section 1.2. But now we need the ducks to FLY............................................................................................................................. 3 Section 1.3. But something went horribly wrong........................................................................................................................... 4 Section 1.4. Joe thinks about inheritance....................................................................................................................................... 5 Section 1.5. Sharpen your pencil..................................................................................................................................................... 5 Section 1.6. How about an interface?............................................................................................................................................. 6 Section 1.7. What would you do if you were Joe?........................................................................................................................... 7 Section 1.8. The one constant in software development................................................................................................................ 8 Section 1.9. Sharpen your pencil.................................................................................................................................................... 8 Section 1.10. Zeroing in on the problem......................................................................................................................................... 9 Section 1.11. Separating what changes from what stays the same............................................................................................... 10 Section 1.12. Designing the Duck Behaviors.................................................................................................................................. 11 Section 1.13. Implementing the Duck Behaviors.......................................................................................................................... 13 Section 1.14. There are no Dumb Questions................................................................................................................................. 14 Section 1.15. Sharpen your pencil.................................................................................................................................................. 14 Section 1.16. Integrating the Duck Behavior................................................................................................................................. 15 Section 1.17. More Integration...................................................................................................................................................... 16 Section 1.18. Testing the Duck code.............................................................................................................................................. 18 Section 1.19. Setting behavior dynamically.................................................................................................................................. 20 Section 1.20. The Big Picture on encapsulated behaviors............................................................................................................ 22 Section 1.21. HAS-A can be better than IS-A................................................................................................................................ 23 Section 1.22. Speaking of Design Patterns................................................................................................................................... 24 Section 1.23. Design Puzzle........................................................................................................................................................... 25 Section 1.24. Overheard at the local diner.................................................................................................................................... 26 Section 1.25. Overheard in the next cubicle.................................................................................................................................. 27 Section 1.26. The power of a shared pattern vocabulary............................................................................................................. 28 Section 1.27. How do I use Design Patterns?............................................................................................................................... 29 Section 1.28. There are no Dumb Questions................................................................................................................................ 29 Section 1.29. Skeptical Developer-Friendly Patterns Guru......................................................................................................... 30 Section 1.30. Tools for your Design Toolbox................................................................................................................................ 32 Section 1.31. Design Puzzle Solution............................................................................................................................................ 34 Section 1.32. Solutions.................................................................................................................................................................. 35
Chapter 1. Welcome to Design Patterns Head First Design Patterns By Eric Freeman, Elisabeth Freeman, Bert Bates, Kathy Sierra Prepared for Ann Cherkis, Safari ID: [email protected] ISBN: 0596007124 Publisher: O'Reilly Print Publication Date: 2004/10/25 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.
www.it-ebooks.info
Chapter 1. Welcome to Design Patterns
Return to Table of Contents
Page 1
Intro to Design Patterns
:HOFRPHWR 5 4 4 'HVLJQ3DWWHUQV 1RZWKDWZH·UHOLYLQJ LQ2EMHFWYLOOHZH·YHMXVWJRW WRJHWLQWR'HVLJQ3DWWHUQV HYHU\RQHLVGRLQJWKHP6RRQ ZH·OOEHWKHKLWRI-LPDQG %HWW\·V:HGQHVGD\QLJKW SDWWHUQVJURXS
6RPHRQHKDVDOUHDG\VROYHG\RXUSUREOHPV,QWKLVFKDSWHU\RX¶OOOHDUQ ZK\DQGKRZ \RXFDQH[SORLWWKHZLVGRPDQGOHVVRQVOHDUQHGE\RWKHUGHYHORSHUVZKR¶YH EHHQGRZQWKHVDPHGHVLJQSUREOHPURDGDQGVXUYLYHGWKHWULS%HIRUHZH¶UHGRQHZH¶OO ORRNDWWKHXVHDQGEHQH¿WVRIGHVLJQSDWWHUQVORRNDWVRPHNH\22GHVLJQSULQFLSOHVDQG ZDONWKURXJKDQH[DPSOHRIKRZRQHSDWWHUQZRUNV7KHEHVWZD\WRXVHSDWWHUQVLVWRORDG \RXUEUDLQZLWKWKHPDQGWKHQUHFRJQL]HSODFHVLQ\RXUGHVLJQVDQGH[LVWLQJDSSOLFDWLRQV ZKHUH\RXFDQDSSO\WKHP,QVWHDGRIFRGHUHXVHZLWKSDWWHUQV\RXJHWH[SHULHQFHUHXVH
WKLVLVDQHZFKDSWHU
Chapter 1. Welcome to Design Patterns Head First Design Patterns By Eric Freeman, Elisabeth Freeman, Bert Bates, Kathy Sierra Prepared for Ann Cherkis, Safari ID: [email protected] ISBN: 0596007124 Publisher: O'Reilly Print Publication Date: 2004/10/25 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.
www.it-ebooks.info
Chapter 1. Welcome to Design Patterns
Return to Table of Contents
Page 2
6LP8'XFN
1\[\IZ\ML_Q\PI[QUXTM;QU=,]KSIXX 2WM_WZS[NWZIKWUXIVa\PI\UISM[IPQOPTa[]KKM[[N]TL]KSXWVL [QU]TI\QWVOIUM;QU=,]KS@DUJV ^ +HDUW0RGHOKHDUW0RGHO QHZ+HDUW0RGHO &RQWUROOHU,QWHUIDFHPRGHO QHZ+HDUW&RQWUROOHUKHDUW0RGHO ` `
$OOZHQHHGWRGRLVFUHDWH WKHFRQWUROOHUDQGSDVVLWD KHDUWPRQLWRU \RXDUHKHUH
Chapter 12. Patterns of Patterns Head First Design Patterns By Eric Freeman, Elisabeth Freeman, Bert Bates, Kathy Sierra Prepared for Ann Cherkis, Safari ID: [email protected] ISBN: 0596007124 Publisher: O'Reilly Print Publication Date: 2004/10/25 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.
www.it-ebooks.info
Chapter 12. Patterns of Patterns
Return to Table of Contents
Page 50
WHVWWKHKHDUWPRGHO
)VLVW_NWZI\M[\Z]V
)LOH(GLW:LQGRZ+HOS&KHFN0\3XOVH
MDYD+HDUW7HVW'ULYH
5XQWKLV
DQG\RX·OOVHHWKLV
+I VL\PM?MJ 1\_I[V¼\TWVOIN\MZ\PM?MJ_I[[X]V\PI\LM^MTWXMZ[[\IZ\MLILIX\QVO\PM5>+\WÅ\\PM JZW_[MZ[MZ^MZUWLMT>`> Óää{Ê-V
i`Õi -Õ`>Þ]Ê"VÌLiÀÊÓ{Ì
UÊ,i}ÃÌÀ>Ì UÊ/ÕÌÀ>Ã UÊ7ÀÃ
«Ã UÊ iÃ}iÃÌ Á UÊiV«ÃiÊ/iV
}ÞÊi8V
>}iÊ i/8®Ê,iVi«Ì `>Þ]Ê"VÌLiÀÊÓxÌ
UÊ,i}ÃÌÀ>Ì UÊ/ÕÌÀ>Ã UÊ7ÀÃ
«Ã UÊ VÌÀ>Ê-Þ«ÃÕ UÊ `ÕV>ÌÀýÊ-Þ«ÃÕ UÊ7iViÊ,iVi«ÌÊEÊ iÜViÀ½ÃÊ,iVi«Ì /ÕiÃ`>Þ]Ê"VÌLiÀÊÓÈÌ
UÊ,i}ÃÌÀ>Ì UÊ/ÕÌÀ>Ã UÊ iÃ}iÃÌ Á UÊ"Ü>À`t UÊ*À>VÌÌiÀÊ,i«ÀÌÃ UÊ/iV
V>Ê*>«iÀà UÊ*>ià UÊÛÌi`Ê-«i>iÀà UÊ>Ã
vÃÒ UÊ Ê/ÕÀ}ÊiVÌÕÀi 7i`iÃ`>Þ]Ê"VÌLiÀÊÓÇÌ
UÊ,i}ÃÌÀ>Ì UÊ/ÕÌÀ>Ã UÊ"Ü>À`t UÊ*À>VÌÌiÀÊ,i«ÀÌÃ UÊ/iV
V>Ê*>«iÀà UÊ*>ià UÊÛÌi`Ê-«i>iÀà UÊ>Ã
vÃÒ UÊ-«iV>Ê ÛiÌÊ>ÌÊÌ
iÊ 6>VÕÛiÀʵÕ>ÀÕ /
ÕÀÃ`>Þ]Ê"VÌLiÀÊÓnÌ
UÊ,i}ÃÌÀ>Ì UÊ/ÕÌÀ>Ã UÊ7ÀÃ
«Ã UÊ"Ü>À`t UÊ*À>VÌÌiÀÊ,i«ÀÌÃ UÊ/iV
V>Ê*>«iÀà UÊ*>ià UÊÛÌi`Ê-«i>iÀà UÊViÊ Ài>Ê-V>Ê ""*-ÊÓääxÊÛÌ>Ì
"
",*",/ -1**",/ ,-
0014-"XJMMCFUIFQSFNJFSHBUIFSJOHPGQSPGFTTJPOBMTGSPNJOEVTUSZ BOEBDBEFNJB BMMTIBSJOHUIFJSFYQFSJFODFTXJUIPCKFDUUFDIOPMPHZBOE JUTPĉTIPPUT0014-"PĉFSTBOFYUSBPSEJOBSZBSSBZQSFTFOUBUJPOTGSPN JOWJUFETQFBLFST UFDIOJDBMQBQFST QSBDUJUJPOFSSFQPSUT FYQFSUQBOFMT EFNPOTUSBUJPOT FEVDBUJPOBMTZNQPTJB XPSLTIPQT EJWFSTFUVUPSJBMTGSPN XPSMEDMBTTMFDUVSFST PVUPGUIFCPYUIJOLJOHBUUIFGSPOUJFSTPGDPNQVUJOH MBUFCSFBLJOHSFTVMUT IBOETPOEFTJHOFYQFSJFODFyBOEPGDPVSTFQMFOUZPG TPDJBMPQQPSUVOJUJFTGPSNJOHMJOHBOEQSPGFTTJPOBMOFUXPSLJOH ͳ BUTKVTUBTBNQMJOHPGXIBUNBLFT0014-"UIFDPOGFSFODFPGDIPJDF GPSTPGUXBSFUFDIOPMPHJTUTGSPNSFDPHOJ[FEBDBEFNJDTUPVOEFSHSBEVBUF TUVEFOUT GSPNJOEVTUSJBMSFTFBSDIFSTUPEFWFMPQFSTBOENBOBHFST GSPNUIF DSFBUPSTPGUFDIOPMPHZUPJUTVTFST
-6 ,
",*",/ -1**",/ ,
-*" -", Ê 9
--"/ -*
-«iV>Ê ÛiÌ\Ê Ê/ÕÀ}ÊiVÌÕÀiÊLÞÊ>Ê>Þ]ÊÓääÎÊ°Ê°Ê/ÕÀ}ÊÜ>À`Ê7iÀ ÀÊÌ
iÊÃiV`ÊÌiÊÊÌÜÊÞi>ÀÃ]Ê""*-ÊÜÊ
ÃÌÊ ½ÃÊ«ÀiÃÌ}ÕÃÊ/ÕÀ}ÊiVÌÕÀi]ÊÌÊLiÊ`iÛiÀi`ÊLÞÊ >Ê>Þ]ÊiÜÞÊ>i`Ê° °/ÕÀ}ÊÜ>À`ÊÜiÀ°Ê iÊÜÌiÃÃÊÌ
ÃÊ
ÃÌÀVÊiÛiÌt
ÛÌi`Ê-«i>iÀÃ ""*-ÊiÞÌiÊ-«i>iÀ ,V
>À`Ê°Ê,>Ã
`]ÊVÀÃvÌÊ,iÃi>ÀV
Ê º/
iÊÕÌÕÀiÊvÊ*À}À>}»
"Ü>À`tÊiÞÌiÊ-«i>iÀ >ÀÊ>iÀ]Ê ÌiÀÃÌi>ÀÊ «ÕÌiÀÊ-ViViÊÃÌÌÕÌi º ÝV«ÕÌ}ÊÊÌ
iÊ9i>ÀÊÓÎä{\ÊÊ-ÕÀÛiÞÊvÊ
wÊÀi`ÊiÊvÀ>ÌÊ/iV
}iû
-ÌiÛiÊV i]Ê ÃÌÀÕÝÊ º `iÊ «iÌiÊÓ\Ê ,i>ÌiÃÊvÊ`iÀÊ-vÌÜ>ÀiÊ ÃÌÀÕVÌ»
iÀLÊ-ÕÌÌiÀ]ÊVÀÃvÌÊ º VÀiÌiÊ>}Õ>}iÃÊÊ6ÀÌÕ>Ê*>ÌvÀû
7>À`Ê Õ}
>]ÊVÀÃvÌ º"LiVÌÃ]Ê*>ÌÌiÀÃ]Ê7Ê>`Ê8*\Ê Ê-ÞÃÌiÃÊvÊ >iû
>Ê6iÀiÕi]Ê>âÊ ºÃ`iÊ>âÊ7iLÊ-iÀÛViû
+WVNMZMVKM[IVL?WZS[PWX[ )VLQN aW]¼LTQSM\WOM\[WUMNIKM\WNIKM\QUM_Q\P \PMXI\\MZV[KWUU]VQ\aJM[]ZM\WKPMKSW]\\PM UIVaXI\\MZV[ZMTI\MLKWVNMZMVKM[IVL_WZS[PWX[ ÞÊ>ÌÊ
ÌÌ«\ÉÉÜÜÜ°Ài}>ÃÌiÀ°VÉ«Ã>Óää{°
Ì T >ÃÌÊ`>ÞÊvÀÊÀi`ÕVi`ÊÀ>ÌiÃ\Ê/
ÕÀÃ`>Þ]Ê£ÈÊ-i«ÌiLiÀÊÓää{ T >ÃÌÊ`>ÞÊÌÊ>`Û>ViÊÀi}ÃÌiÀ\Ê/
ÕÀÃ`>Þ]ÊÇÊ"VÌLiÀÊÓää{
6ÃÌÊÌ
iÊ""*-ÊÜiLÃÌiÊ
ÌÌ«\ÉÉ«Ã>°À}ÊvÀÊvÕÊVviÀiViÊ«À}À>Ê`iÌ>ð
\RXDUHKHUH
Chapter 13. Patterns in the Real World Head First Design Patterns By Eric Freeman, Elisabeth Freeman, Bert Bates, Kathy Sierra Prepared for Ann Cherkis, Safari ID: [email protected] ISBN: 0596007124 Publisher: O'Reilly Print Publication Date: 2004/10/25 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.
www.it-ebooks.info
Chapter 13. Patterns in the Real World
Return to Table of Contents
Page 28
SDWWHUQV]RR