Tải bản đầy đủ (.pdf) (654 trang)

head first design pattern

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (41.3 MB, 654 trang )

Table of Contents
Copyright 1
Dedication 2
Preface 3
Authors/Developers of Head First Design Patterns 7
Creators of the Head First series (and co-conspirators on this book) 8
Intro 9
Chapter 1. Welcome to Design Patterns 21
Section 1.1. It started with a simple SimUDuck app 22
Section 1.2. But now we need the ducks to FLY 23
Section 1.3. But something went horribly wrong 24
Section 1.4. Joe thinks about inheritance 25
Section 1.5. Sharpen your pencil 25
Section 1.6. How about an interface? 26
Section 1.7. What would you do if you were Joe? 27
Section 1.8. The one constant in software development 28
Section 1.9. Sharpen your pencil 28
Section 1.10. Zeroing in on the problem 29
Section 1.11. Separating what changes from what stays the same 30
Section 1.12. Designing the Duck Behaviors 31
Section 1.13. Implementing the Duck Behaviors 33
Section 1.14. There are no Dumb Questions 34
Section 1.15. Sharpen your pencil 34
Section 1.16. Integrating the Duck Behavior 35
Section 1.17. More Integration 36
Section 1.18. Testing the Duck code 38
Section 1.19. Setting behavior dynamically 40
Section 1.20. The Big Picture on encapsulated behaviors 42
Section 1.21. HAS-A can be better than IS-A 43
Section 1.22. Speaking of Design Patterns 44


Section 1.23. Design Puzzle 45
Section 1.24. Overheard at the local diner 46
Section 1.25. Overheard in the next cubicle 47
Section 1.26. The power of a shared pattern vocabulary 48
Section 1.27. How do I use Design Patterns? 49
Section 1.28. There are no Dumb Questions 49
Section 1.29. Skeptical Developer-Friendly Patterns Guru 50
Section 1.30. Tools for your Design Toolbox 52
Section 1.31. Design Puzzle Solution 54
Section 1.32. Solutions 55
Chapter 2. Keeping your Objects in the know 56
Section 2.1. The Weather Monitoring application overview 58
Section 2.2. Unpacking the WeatherData class 59
Section 2.3. What do we know so far ? 60
Section 2.4. Taking a first, misguided SWAG at the Weather Station 61
Section 2.5. Sharpen your pencil 61
Section 2.6. What's wrong with our implementation? 62
Section 2.7. Meet the Observer Pattern 63
Section 2.8. Publishers + Subscribers = Observer Pattern 64
Section 2.9. A day in the life of the Observer Pattern 65
Section 2.10. Five minute drama: a subject for observation 67
Section 2.11. Two weeks later 69
Section 2.12. The Observer Pattern defined 70
Section 2.13. The Observer Pattern defined: the class diagram 71
Section 2.14. The power of Loose Coupling 72
Head First Design Patterns
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:

Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
Section 2.15. Sharpen your pencil 73
Section 2.16. Cubicle conversation 74
Section 2.17. Designing the Weather Station 75
Section 2.18. Implementing the Weather Station 76
Section 2.19. Implementing the Subject interface in WeatherData 77
Section 2.20. Now, let's build those display elements 78
Section 2.21. There are no Dumb Questions 78
Section 2.22. Power up the Weather Station 79
Section 2.23. Sharpen your pencil 80
Section 2.24. Using Java's built-in Observer Pattern 83
Section 2.25. How Java's built-in Observer Pattern works 84
Section 2.26. Reworking the Weather Station with the built-in support 86
Section 2.27. Now, let's rework the CurrentConditionsDisplay 87
Section 2.28. Exercise: Code Magnets 88
Section 2.29. Running the new code 89
Section 2.30. The dark side of java.util.Observable 90
Section 2.31. Other places you'll find the Observer Pattern in the JDK 91
Section 2.32. And the code 92
Section 2.33. Tools for your Design Toolbox 93
Section 2.34. Exercise: Design Principle Challenge 94
Section 2.35. Exercise solutions: Design Principle Challenge 96
Section 2.36. Code Magnets: Exercise solutions 97
Chapter 3. Decorating Objects 98
Section 3.1. Welcome to Starbuzz Coffee 99
Section 3.2. Sharpen your pencil 102
Section 3.3. Sharpen your pencil 103

Section 3.4. The Open-Closed Principle 105
Section 3.5. There are no Dumb Questions 106
Section 3.6. Meet the Decorator Pattern 107
Section 3.7. Constructing a drink order with Decorators 108
Section 3.8. The Decorator Pattern defined 110
Section 3.9. Decorating our Beverages 111
Section 3.10. Cubicle Conversation 112
Section 3.11. New barista training 113
Section 3.12. Sharpen your pencil 113
Section 3.13. Writing the Starbuzz code 114
Section 3.14. Coding beverages 115
Section 3.15. Coding condiments 116
Section 3.16. Sharpen your pencil 116
Section 3.17. Serving some coffees 117
Section 3.18. There are no Dumb Questions 118
Section 3.19. Sharpen your pencil 118
Section 3.20. Real World Decorators: Java I/O 119
Section 3.21. Decorating the java.io classes 120
Section 3.22. Writing your own Java I/O Decorator 121
Section 3.23. Test out your new Java I/O Decorator 122
Section 3.24. Patterns Exposed 123
Section 3.25. Tools for your Design Toolbox 124
Section 3.26. Exercise solutions 125
Section 3.27. Exercise solutions 126
Chapter 4. Baking with OO Goodness 127
Section 4.1. Brain Power 129
Section 4.2. Identifying the aspects that vary 130
Section 4.3. But the pressure is on to add more pizza types 131
Section 4.4. Encapsulating object creation 132
Section 4.5. Building a simple pizza factory 133

Section 4.6. There are no Dumb Questions 133
Section 4.7. Reworking the PizzaStore class 134
Section 4.8. The Simple Factory defined 135
Section 4.9. Franchising the pizza store 136
Head First Design Patterns
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
Section 4.10. A framework for the pizza store 138
Section 4.11. Allowing the subclasses to decide 139
Section 4.12. Let's make a PizzaStore 141
Section 4.13. Declaring a factory method 143
Section 4.14. Let's see how it works: ordering pizzas with the pizza factory method 144
Section 4.15. Let's check out how these pizzas are really made to order Behind the Scenes 145
Section 4.16. We're just missing one thing: PIZZA! 146
Section 4.17. Now we just need some concrete subclasses how about defining New York and Chicago style cheese pizzas?
147
Section 4.18. It's finally time to meet the Factory Method Pattern 149
Section 4.19. Another perspective: parallel class hierarchies 150
Section 4.20. Design Puzzle 151
Section 4.21. Factory Method Pattern defined 152
Section 4.22. There are no Dumb Questions 153
Section 4.23. A very dependent PizzaStore 155
Section 4.24. Looking at object dependencies 156
Section 4.25. The Dependency Inversion Principle 157

Section 4.26. Applying the Principle 158
Section 4.27. Inverting your thinking 160
Section 4.28. A few guidelines to help you follow the Principle 161
Section 4.29. Meanwhile, back at the PizzaStore 162
Section 4.30. Families of ingredients 163
Section 4.31. Building the ingredient factories 164
Section 4.32. Building the New York ingredient factory 165
Section 4.33. Sharpen your pencil 166
Section 4.34. Reworking the pizzas 167
Section 4.35. Reworking the pizzas, continued 168
Section 4.36. Code Up Close 169
Section 4.37. Revisiting our pizza stores 170
Section 4.38. What have we done? 171
Section 4.39. More pizza for Ethan and Joel 172
Section 4.40. Abstract Factory Pattern defined 174
Section 4.41. Patterns Exposed 176
Section 4.42. Factory Method and Abstract Factory compared 178
Section 4.43. Tools for your Design Toolbox 180
Section 4.44. Exercise solutions 182
Section 4.45. Sharpen your pencil 182
Section 4.46. Design Puzzle Solution 183
Section 4.47. A very dependent PizzaStore 184
Section 4.48. Sharpen your pencil 184
Section 4.49. Sharpen your pencil 185
Section 4.50. Puzzle Solution 186
Chapter 5. One of a Kind Objects 187
Section 5.1. The Little Singleton: A small Socratic exercise in the style of The Little Lisper 189
Section 5.2. Dissecting the classic Singleton Pattern implementation 191
Section 5.3. Patterns Exposed 192
Section 5.4. The Chocolate Factory 193

Section 5.5. Sharpen your pencil 194
Section 5.6. Singleton Pattern defined 195
Section 5.7. Hershey, PA: Houston, we have a problem 196
Section 5.8. BE the JVM 197
Section 5.9. Dealing with multithreading 198
Section 5.10. Can we improve multithreading? 199
Section 5.11. Meanwhile, back at the Chocolate Factory 201
Section 5.12. Congratulations! 201
Section 5.13. there are no Dumb Questions 202
Section 5.14. Tools for your Design Toolbox 204
Section 5.15. Exercise solutions 206
Section 5.16. Exercise Solutions 207
Section 5.17. Exercise solutions 208
Head First Design Patterns
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
Chapter 6. Encapsulating Invocation 209
Section 6.1. Free hardware! Let's check out the Remote Control 211
Section 6.2. Taking a look at the vendor classes 212
Section 6.3. Cubicle Conversation 213
Section 6.4. Meanwhile, back at the Diner , or, A brief introduction to the Command Pattern 215
Section 6.5. Let's study the interaction in a little more detail 216
Section 6.6. The Objectville Diner roles and responsibilities 217
Section 6.7. From the Diner to the Command Pattern 219

Section 6.8. Our first command object 221
Section 6.9. Using the command object 222
Section 6.10. Creating a simple test to use the Remote Control 222
Section 6.11. Sharpen your pencil 223
Section 6.12. The Command Pattern defined 224
Section 6.13. The Command Pattern defined: the class diagram 225
Section 6.14. BRAIN POWER 225
Section 6.15. Assigning Commands to slots 227
Section 6.16. Implementing the Remote Control 228
Section 6.17. Implementing the Commands 229
Section 6.18. Putting the Remote Control Through Its Paces 230
Section 6.19. Now, Let's Check Out the Execution of Our Remote Control Test 231
Section 6.20. Time to Write That Documentation 233
Section 6.21. What are we Doing? 234
Section 6.22. Time to QA That Undo Button! 237
Section 6.23. Using State to Implement Undo 238
Section 6.24. Adding Undo to the Ceiling Fan Commands 239
Section 6.25. Get Ready to Test the Ceiling Fan 240
Section 6.26. Testing the Ceiling Fan 241
Section 6.27. Every Remote Needs a Party Mode! 242
Section 6.28. Using a Macro Command 243
Section 6.29. There are no Dumb Questions 245
Section 6.30. More Uses of the Command Pattern: Queuing Requests 246
Section 6.31. More Uses of the Command Pattern: Logging Requests 247
Section 6.32. Tools for your Design Toolbox 248
Section 6.33. Exercise Solutions 250
Section 6.34. Exercise Solutions 251
Chapter 7. Being Adaptive 252
Section 7.1. Adapters all around us 253
Section 7.2. Object oriented adapters 254

Section 7.3. If it walks like a duck and quacks like a duck, then it must might be a duck turkey wrapped with a duck adapter
255
Section 7.4. Test drive the adapter 257
Section 7.5. The Adapter Pattern explained 258
Section 7.6. There are no Dumb Questions 259
Section 7.7. Adapter Pattern defined 260
Section 7.8. Object and class adapters 261
Section 7.9. Duck Magnets 262
Section 7.10. Duck Magnets Answer 263
Section 7.11. Fireside Chats 264
Section 7.12. Real world adapters 265
Section 7.13. Adapting an Enumeration to an Iterator 266
Section 7.14. Fireside Chats 269
Section 7.15. And now for something different 270
Section 7.16. Home Sweet Home Theater 272
Section 7.17. Watching a movie (the hard way) 273
Section 7.18. Lights, Camera, Facade! 275
Section 7.19. There are no Dumb Questions 277
Section 7.20. Constructing your home theater facade 278
Section 7.21. Implementing the simplified interface 279
Section 7.22. Time to watch a movie (the easy way) 280
Section 7.23. Facade Pattern defined 281
Head First Design Patterns
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use

requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
Section 7.24. The Principle of Least Knowledge 282
Section 7.25. How NOT to Win Friends and Influence Objects 283
Section 7.26. there are no Dumb Questions 284
Section 7.27. The Facade and the Principle of Least Knowledge 286
Section 7.28. Tools for your Design Toolbox 287
Section 7.29. Exercise solutions 289
Section 7.30. Exercise solutions 290
Section 7.31. Exercise solutions 291
Chapter 8. Encapsulating Algorithms 292
Section 8.1. It's time for some more caffeine 293
Section 8.2. Whipping up some coffee and tea classes (in Java) 294
Section 8.3. Sir, may I abstract your Coffee, Tea? 297
Section 8.4. Taking the design further 298
Section 8.5. Abstracting prepareRecipe() 299
Section 8.6. What have we done? 302
Section 8.7. Meet the Template Method 303
Section 8.8. Let's make some tea : Behind the Scenes 304
Section 8.9. What did the Template Method get us? 305
Section 8.10. Template Method Pattern defined 306
Section 8.11. Hooked on Template Method 309
Section 8.12. Using the hook 310
Section 8.13. Let's run the TestDrive 311
Section 8.14. there are no Dumb Questions 312
Section 8.15. The Hollywood Principle 313
Section 8.16. The Hollywood Principle and Template Method 314
Section 8.17. there are no Dumb Questions 315
Section 8.18. Template Methods in the Wild 316
Section 8.19. Sorting with Template Method 317
Section 8.20. We've got some ducks to sort 318

Section 8.21. What is compareTo()? 318
Section 8.22. Comparing Ducks and Ducks 319
Section 8.23. Let's sort some Ducks 320
Section 8.24. The making of the sorting duck machine 321
Section 8.25. there are no Dumb Questions 322
Section 8.26. Swingin' with Frames 323
Section 8.27. Applets 324
Section 8.28. Fireside Charts 325
Section 8.29. Tools for your Design Toolbox 328
Section 8.30. Exercise solutions 329
Section 8.31. Exercise solutions 330
Chapter 9. Well-Managed Collections 331
Section 9.1. Breaking News: Objectville Diner Merge and Objectville Pancake House 332
Section 9.2. Check out the Menu Items 333
Section 9.3. Lou and Mel's Menu implementations 334
Section 9.4. What's the problem with having two different menu representations? 336
Section 9.5. Sharpen your pencil 338
Section 9.6. What now? 338
Section 9.7. Can we encapsulate the iteration? 339
Section 9.8. Meet the Iterator Pattern 341
Section 9.9. Adding an Iterator to DinerMenu 342
Section 9.10. Reworking the Diner Menu with Iterator 343
Section 9.11. Exercise 343
Section 9.12. Fixing up the Waitress code 344
Section 9.13. Testing our code 345
Section 9.14. What have we done so far? 346
Section 9.15. What we have so far 347
Section 9.16. Making some improvements 348
Section 9.17. There are no Dumb Questions 348
Section 9.18. Cleaning things up with java.util.Iterator 349

Section 9.19. We are almost there 350
Head First Design Patterns
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
Section 9.20. What does this get us? 351
Section 9.21. Iterator Pattern defined 352
Section 9.22. There are no Dumb Questions 354
Section 9.23. Single Responsibility 355
Section 9.24. BRAIN POWER 356
Section 9.25. BRAIN2 POWER 356
Section 9.26. Taking a look at the Café Menu 358
Section 9.27. Sharpen your pencil 358
Section 9.28. Reworking the Café Menu code 359
Section 9.29. Code Up Close 359
Section 9.30. Adding the Café Menu to the Waitress 360
Section 9.31. Breakfast, lunch AND dinner 361
Section 9.32. What did we do? 362
Section 9.33. We decoupled the Waitress 362
Section 9.34. and we made the Waitress more extensible 363
Section 9.35. But there's more! 363
Section 9.36. Iterators and Collections 364
Section 9.37. Iterators and Collections in Java 5 365
Section 9.38. Code Magnets 366
Section 9.39. Is the Waitress ready for prime time? 367

Section 9.40. Just when we thought it was safe 369
Section 9.41. What do we need? 370
Section 9.42. The Composite Pattern defined 372
Section 9.43. Designing Menus with Composite 375
Section 9.44. Implementing the Menu Component 376
Section 9.45. Implementing the Menu Item 377
Section 9.46. Implementing the Composite Menu 378
Section 9.47. Getting ready for a test drive 380
Section 9.48. Now for the test drive 381
Section 9.49. Getting ready for a test drive 382
Section 9.50. Flashback to Iterator 384
Section 9.51. The Composite Iterator 385
Section 9.52. The Null Iterator 388
Section 9.53. Give me the vegetarian menu 389
Section 9.54. The magic of Iterator & Composite together 390
Section 9.55. Patterns Exposed 392
Section 9.56. WHO DOES WHAT? 395
Section 9.57. Tools for your Design Toolbox 396
Section 9.58. Exercise solutions 397
Section 9.59. Code Magnets Solution 398
Section 9.60. WHO DOES WHAT? 399
Section 9.61. Exercise Solution 400
Chapter 10. The State of Things 401
Section 10.1. Java Breakers 402
Section 10.2. Cubicle Conversation 403
Section 10.3. State machines 101 404
Section 10.4. Writing the code 406
Section 10.5. In-house testing 408
Section 10.6. You knew it was coming a change request! 410
Section 10.7. Design Puzzle 411

Section 10.8. The messy STATE of things 412
Section 10.9. The new design 414
Section 10.10. Defining the State interfaces and classes 415
Section 10.11. Implementing our State classes 417
Section 10.12. Reworking the Gumball Machine 418
Section 10.13. Implementing more states 420
Section 10.14. Let's take a look at what we've done so far 423
Section 10.15. Sharpen your pencil 425
Section 10.16. The State Pattern defined 426
Section 10.17. there are no Dumb Questions 428
Head First Design Patterns
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
Section 10.18. We still need to finish the Gumball 1 in 10 game 429
Section 10.19. Finishing the game 430
Section 10.20. Demo for the CEO of Mighty Gumball, Inc 431
Section 10.21. there are no Dumb Questions 432
Section 10.22. Sanity check 433
Section 10.23. We almost forgot! 436
Section 10.24. Sharpen your pencil 437
Section 10.25. Tools for your Design Toolbox 439
Section 10.26. Exercise solutions 440
Section 10.27. Exercise solutions 441
Chapter 11. Controlling Object Access 445

Section 11.1. Coding the Monitor 447
Section 11.2. Testing the Monitor 448
Section 11.3. The role of the 'remote proxy' 450
Section 11.4. Adding a remote proxy to the Gumball Machine monitoring code 452
Section 11.5. Remote methods 101 453
Section 11.6. How the method call happens 454
Section 11.7. Java RMI, the Big Picture 456
Section 11.8. Making the Remote service 457
Section 11.9. Step one: make a Remote interface 458
Section 11.10. Step two: make a Remote implementation 459
Section 11.11. Step three: generate stubs and skeletons 460
Section 11.12. Step four: run rmiregistry 460
Section 11.13. Step five: start the service 460
Section 11.14. How does the client get the stub object? 462
Section 11.15. Watch it 465
Section 11.16. Back to our GumballMachine remote proxy 466
Section 11.17. Getting the GumballMachine ready to be a remote service 467
Section 11.18. Registering with the RMI registry 469
Section 11.19. Now for the GumballMonitor client 470
Section 11.20. Writing the Monitor test drive 471
Section 11.21. Another demo for the CEO of Mighty Gumball 472
Section 11.22. And now let's put the monitor in the hands of the CEO. Hopefully this time he'll love it: 473
Section 11.23. Behind the Scenes 474
Section 11.24. The Proxy Pattern defined 476
Section 11.25. Get ready for Virtual Proxy 478
Section 11.26. Displaying CD covers 479
Section 11.27. Designing the CD cover Virtual Proxy 480
Section 11.28. Writing the Image Proxy 481
Section 11.29. Design Puzzle 484
Section 11.30. Testing the CD Cover Viewer 485

Section 11.31. What did we do?: Behin the scenes 486
Section 11.32. there are no Dumb Questions 487
Section 11.33. Fireside Charts 488
Section 11.34. Using the Java API's Proxy to create a protection proxy 490
Section 11.35. Matchmaking in Objectville 491
Section 11.36. The PersonBean implementation 492
Section 11.37. Five minute drama: protecting subjects 494
Section 11.38. Big Picture: creating a Dynamic Proxy for the PersonBean 495
Section 11.39. Step one: creating Invocation Handlers 496
Section 11.40. Creating Invocation Handlers continued 497
Section 11.41. Exercise 498
Section 11.42. Step two: creating the Proxy class and instantiating the Proxy object 499
Section 11.43. Sharpen your pencil 499
Section 11.44. Testing the matchmaking service 500
Section 11.45. Running the code 501
Section 11.46. there are no Dumb Questions 502
Section 11.47. WHO DOES WHAT 503
Section 11.48. The Proxy Zoo 504
Section 11.49. Tools for your Design Toolbox 507
Head First Design Patterns
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
Section 11.50. Exercise solutions 508
Section 11.51. Exercise solutions 509

Section 11.52. Ready-bake Code: The code for the CD Cover Viewer 510
Section 11.53. Ready-bake Code: The code for the CD Cover Viewer, continued 512
Chapter 12. Patterns of Patterns 514
Section 12.1. Working together 515
Section 12.2. Duck reunion 516
Section 12.3. There are no Dumb Questions 537
Section 12.4. What did we do? 538
Section 12.5. A bird's duck's eye view: the class diagram 539
Section 12.6. The King of Compound Patterns 541
Section 12.7. Meet the Model-View-Controller 544
Section 12.8. A closer look 545
Section 12.9. There are no Dumb Questions 546
Section 12.10. Looking at MVC through patterns-colored glasses 547
Section 12.11. Using MVC to control the beat 549
Section 12.12. Meet the Java DJ View 549
Section 12.13. Putting the pieces together 551
Section 12.14. Building the pieces 552
Section 12.15. Now let's have a look at the concrete BeatModel class: 553
Section 12.16. The View 554
Section 12.17. BRAIN POWER 554
Section 12.18. Implementing the View 555
Section 12.19. Implementing the View, continued 556
Section 12.20. Now for the Controller 557
Section 12.21. And here's the implementation of the controller: 558
Section 12.22. Putting it all together 559
Section 12.23. And now for a test run 559
Section 12.24. Exploring Strategy 560
Section 12.25. Adapting the Model 561
Section 12.26. Now we're ready for a HeartController 562
Section 12.27. And now for a test run 563

Section 12.28. MVC and the Web 564
Section 12.29. Model 2 is more than just a clean design 565
Section 12.30. Model 2: DJ'ing from a cell phone 566
Section 12.31. Now we need a view 569
Section 12.32. Putting Model 2 to the test 570
Section 12.33. Design Patterns and Model 2 572
Section 12.34. Observer 572
Section 12.35. Strategy 573
Section 12.36. There are no Dumb Questions 574
Section 12.37. Tools for your Design Toolbox 575
Section 12.38. Exercise solutions 576
Section 12.39. Ready-bake Code 579
Section 12.40. Ready-bake Code: The View 583
Section 12.41. The Controller 586
Section 12.42. The Heart Model 588
Section 12.43. The Heart Adapter 590
Section 12.44. The Controller 591
Chapter 13. Patterns in the Real World 592
Section 13.1. Design Pattern defined 594
Section 13.2. Looking more closely at the Design Pattern definition 596
Section 13.3. Geek Bits 597
Section 13.4. there are no Dumb Questions 601
Section 13.5. So you wanna be a Design Patterns writer 602
Section 13.6. Organizing Design Patterns 604
Section 13.7. Solution: Pattern Categories 605
Section 13.8. there are no Dumb Questions 606
Section 13.9. Thinking in Patterns 609
Section 13.10. Your Mind on Patterns 612
Head First Design Patterns
Head First Design Patterns

Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
Section 13.11. Don't forget the power of the shared vocabulary 614
Section 13.12. Cruisin' Object ville with the Gang of Four 616
Section 13.13. Your journey has just begun 617
Section 13.14. The Patterns Zoo 619
Section 13.15. Annihilating evil with Anti-Patterns 621
Section 13.16. Tools for your Design Toolbox 623
Section 13.17. Leaving Objectville 624
Section 13.18. Exercise solutions 625
Appendix A. Leftover Patterns 626
Section A.1. Bridge 627
Section A.2. Why use the Bridge Pattern? 628
Section A.3. Builder 629
Section A.4. Why use the Builder Pattern? 630
Section A.5. Chain of Responsibility 631
Section A.6. How to use the Chain of Responsibility Pattern 632
Section A.7. Flyweight 633
Section A.8. Why use the Flyweight Pattern? 634
Section A.9. Interpreter 635
Section A.10. How to implement an interpreter 636
Section A.11. Mediator 637
Section A.12. Mediator in action 638
Section A.13. Memento 639
Section A.14. The Memento at work 640

Section A.15. Prototype 641
Section A.16. Prototype to the rescue 642
Section A.17. Visitor 643
Section A.18. The Visitor drops by 644
Head First Design Patterns
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
+HDG)LUVW'HVLJQ3DWWHUQV
Ja-ZQK.ZMMUIV-TQ[IJM\P.ZMMUIV3I\Pa;QMZZIIVL*MZ\*I\M[
+WXaZQOP\7¼:MQTTa5MLQI1VK)TTZQOP\[ZM[MZ^ML
8ZQV\MLQV\PM=VQ\ML;\I\M[WN )UMZQKI
8]JTQ[PMLJa7¼:MQTTa5MLQI1VK/ZI^MV[\MQV0QOP_Ia6WZ\P;MJI[\WXWT+)!
7¼:MQTTa5MLQIJWWS[UIaJMX]ZKPI[MLNWZML]KI\QWVITJ][QVM[[WZ[ITM[XZWUW\QWVIT][M7VTQVMMLQ\QWV[IZM
IT[WI^IQTIJTMNWZUW[\\Q\TM[[INIZQWZMQTTaKWU.WZUWZMQVNWZUI\QWVKWV\IK\W]ZKWZXWZI\MQV[\Q\]\QWVIT[ITM[
LMXIZ\UMV\" !! !! WZKWZXWZI\M(WZMQTTaKWU
(GLWRU 5QSM4W]SQLM[
&RYHU'HVLJQHU -TTQM>WTKSPI][MV
3DWWHUQ:UDQJOHUV -ZQK.ZMMUIV-TQ[IJM\P.ZMMUIV
)DFDGH'HFRUDWLRQ -TQ[IJM\P.ZMMUIV
6WUDWHJ\ 3I\Pa;QMZZIIVL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 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
<W\PM/IVOWN .W]Z_PW[MQV[QOP\IVLM`XMZ\Q[MQVKIX\]ZQVO
IVLKWUU]VQKI\QVO,M[QOV8I\\MZV[PI[KPIVOML\PMNIKMWN 
[WN\_IZMLM[QOVNWZM^MZIVLJM\\MZML\PMTQ^M[WN LM^MTWXMZ[
\PZW]OPW]\\PM_WZTL
*]\[MZQW][Ta_PMVIZM_MOWQVO\W[MMI[MKWVLMLQ\QWV')N\MZITT
Q\¼[JMMVWVTa\MVaMIZ[
Head First Design Patterns Page 2 Return to Table of Contents

Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
Licensed by
Zheng Yuan
3UDLVHIRU
+HDG)LUVW'HVLJQ3DWWHUQV
¹1ZMKMQ^ML\PMJWWSaM[\MZLIaIVL[\IZ\ML\WZMILQ\WV\PM_IaPWUMIVL1KW]TLV¼\[\WX1\WWSQ\\W\PM
OaUIVL1M`XMK\XMWXTM[I_UM[UQTQVOITW\_PQTM1_I[M`MZKQ[QVOIVLZMILQVO<PQ[Q[\Z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QV\W\PMZMITUWN XI\\MZV[ITIVL_PMZMKWUXTM`\PQVO[JMKWUM[QUXTMJ]\_PMZM[QUXTM
\PQVO[KIVIT[WJMKWUMKWUXTM`1KIV\PQVSWN VWJM\\MZ\W]ZO]QLM[\PIV\PM.ZMMUIV[º
 ¸5QSW5I\[]U]ZI1VL][\Za)VITa[\<PM5QLLTM_IZM+WUXIVa
.WZUMZ+PQMN 2I^I-^IVOMTQ[\;]V5QKZW[a[\MU[
¹1TI]OPML1KZQMLQ\UW^MLUMº
 ¸,IVQMT;\MQVJMZO-LQ\WZQV+PQMNRI^IVM\
¹5aÅZ[\ZMIK\QWV_I[\WZWTTWV\PMÆWWZTI]OPQVO)N\MZ1XQKSMLUa[MTN ]X1ZMITQbML\PI\VW\WVTaQ[\PM
JWWS\MKPVQKITTaIKK]ZI\MQ\Q[\PMMI[QM[\\W]VLMZ[\IVLQV\ZWL]K\QWV\WLM[QOVXI\\MZV[\PI\1PI^M[MMVº
 ¸,Z<QUW\Pa)*]LL)[[WKQI\M8ZWNM[[WZWN +WUX]\MZ;KQMVKMI\
 7ZMOWV;\I\M=VQ^MZ[Q\aIVLI]\PWZWN UWZM\PIVILWbMVJWWS[
 QVKT]LQVO¹+NWZ2I^I8ZWOZIUUMZ[º
¹2MZZa:QKMZ]V[XI\\MZV[JM\\MZ\PIVIVaZMKMQ^MZQV\PM6.4J]\\PM.ZMMUIV[PI^MW]\Z]VPQU
;MZQW][Ta\PQ[Q[WVMWN \PMN]VVQM[\IVL[UIZ\M[\JWWS[WV[WN\_IZMLM[QOV1¼^MM^MZZMILº
 ¸)IZWV4I*MZOM>8<MKPVWTWOa-;86KWU
Head First Design Patterns Page 3 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
0RUH3UDLVHIRU
+HDG)LUVW'HVLJQ3DWWHUQV
¹/ZMI\KWLMLM[QOVQ[ÅZ[\IVLNWZMUW[\OZMI\QVNWZUI\QWVLM[QOV)KWLMLM[QOVMZQ[\MIKPQVOIKWU
X]\MZPW_\WLW[WUM\PQVOIVLQ\Q[VW[]ZXZQ[M\PI\IOZMI\\MIKPMZWN KWUX]\MZ[[PW]TL\]ZVW]\\WJM
IOZMI\\MIKPMZWN XZWOZIUUMZ[<PQ[JWWS¼[ILUQZIJTMKTIZQ\aP]UWZIVL[]J[\IV\QITLW[M[WN KTM^MZ
UISMQ\\PM[WZ\WN JWWS\PI\PMTX[M^MVVWVXZWOZIUUMZ[\PQVS_MTTIJW]\XZWJTMU[WT^QVOº

 ¸+WZa,WK\WZW_KWMLQ\WZWN *WQVO*WQVO
 IVLI]\PWZWN ¹,W_VIVL7]\QV\PM5IOQK3QVOLWUº
 IVL¹;WUMWVM+WUM[\W<W_V;WUMWVM4MI^M[<W_Vº
¹<PMZM¼[IVWTL[IaQVOQV\PMKWUX]\MZIVL^QLMWOIUMJ][QVM[[·_MTTQ\KIV¼\JM\PI\WTLJMKI][M\PM
LQ[KQXTQVMQ[VW\ITT\PI\WTL·IVLQ\OWM[[WUM\PQVOTQSM\PQ[",M[QOVQ[4QNM?PI\¼[XIZ\QK]TIZTaK]ZQW][
IJW]\\PQ[XPZI[MQ[\PI\M^MV\WLIaITUW[\VWWVM_PW_WZS[I\\PMKZIN\WN KZMI\QVOMTMK\ZWVQKOIUM[
KIVIOZMMWV_PI\Q\UMIV[\W¹LM[QOVºIOIUM1[\PMLM[QOVMZI[WN\_IZMMVOQVMMZ')VIZ\LQZMK\WZ'
)[\WZa\MTTMZ')VIZKPQ\MK\WZIJ]QTLMZ')XQ\K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QVM
¹2][\\PMZQOP\\WVMNWZ\PMOMMSMLW]\KI[]ITKWWTO]Z]KWLMZQVITTWN ][<PMZQOP\ZMNMZMVKMNWZ
XZIK\QKITLM^MTWXUMV\[\ZI\MOQM[¸OM\[UaJZIQVOWQVO_Q\PW]\PI^QVO\W[TWO\PZW]OPIJ]VKPWN \QZML
[\ITMXZWNM[[WZ[XMISº
 ¸<ZI^Q[3ITIVQKS.W]VLMZWN ;KW]ZIVL:ML;_WW[P
 5MUJMZWN \PM51<<:
¹<PQ[JWWSKWUJQVM[OWWLP]UWZ[OZMI\M`IUXTM[IVLQVLMX\PSVW_TMLOMWN,M[QOV8I\\MZV[QV
[]KPI_Ia\PI\UISM[TMIZVQVON]V*MQVOQV\PMMV\MZ\IQVUMV\\MKPVWTWOaQVL][\Za1IUQV\ZQO]ML
Ja\PM0WTTa_WWL8ZQVKQXTMIVL\PMPWUM\PMI\MZ.IKILM8I\\MZV\WVIUMINM_<PM]VLMZ[\IVLQVO

WN ,M[QOV8I\\MZV[VW\WVTaPMTX[][KZMI\MZM][IJTMIVLUIQV\IQVIJTMY]ITQ\a[WN\_IZMJ]\IT[WPMTX[
[PIZXMVW]ZXZWJTMU[WT^QVO[SQTT[IKZW[[ITTXZWJTMULWUIQV[<PQ[JWWSQ[IU][\ZMILNWZITTKWU
X]\MZXZWNM[[QWVIT[IVL[\]LMV\[º
 ¸6M_\WV4MM.W]VLMZIVL-LQ\WZQV+PQMN)[[WKQI\QWVNWZ+WUX]\QVO
 5IKPQVMZa¼[)+5+WUX]\MZ[QV-V\MZ\IQVUMV\IKUKQMWZO
Head First Design Patterns Page 4 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
3UDLVHIRUWKH
+HDG)LUVW
DSSURDFK
¹2I^I\MKPVWTWOaQ[M^MZa_PMZM¸QVUWJQTMXPWVM[KIZ[KIUMZI[XZQV\MZ[OIUM[8,)[)<5[[UIZ\
KIZL[OI[X]UX[[XWZ\[[\ILQ]U[UMLQKITLM^QKM[?MJKIU[[MZ^MZ[aW]VIUMQ\1N aW]LM^MTWX
[WN\_IZMIVLPI^MV¼\TMIZVML2I^IQ\¼[LMÅVQ\MTa\QUM\WLQ^MQV¸0MIL.QZ[\º
 ¸;KW\\5K6MITa;]V5QKZW[a[\MU[+PIQZUIV8ZM[QLMV\IVL+-7
¹1\¼[NI[\QZZM^MZMV\N]VIVLMVOIOQVO*MKIZMN]T¸aW]UQOP\IK\]ITTaTMIZV[WUM\PQVOº
 ¸3MV)ZVWTLNWZUMZ;MVQWZ-VOQVMMZI\;]V5QKZW[a[\MU[
 +WI]\PWZ_Q\P2IUM[/W[TQVOKZMI\WZWN 2I^I
 ¹<PM2I^I8ZWOZIUUQVO4IVO]IOMº
¹0MIL.QZ[\2I^IQ[TQSM5WV\a8a\PWVUMM\[\PMOIVOWN NW]Z\PM\M`\Q[JZWSMV]X[W_MTTJaX]bbTM[IVL
[\WZQM[Y]QbbM[IVLM`IUXTM[\PI\aW]KW^MZOZW]VLTQSMVWKWUX]\MZJWWSJMNWZMº
 ¸,W]OTI[:W_M+WT]UJQI2I^I=[MZ[/ZW]X
¹»0MIL.QZ[\2I^I¼OQ^M[VM_UMIVQVO\W\PMQZUIZSM\QVOXPZI[MH<PMZM¼[IV7:MQTTaNWZ\PI\H1XQKSML
\PQ[]XJMKI][M[M^MZITW\PMZ[1ZM[XMK\PILLM[KZQJMLQ\QV\MZU[TQSM»ZM^WT]\QWVIZa¼IVLILM[KZQJMLI

ZILQKITTaLQNNMZMV\IXXZWIKP\W\PM\M`\JWWS<PMa_MZMIZMZQOP\1V\aXQKIT7¼:MQTTaNI[PQWV\PMa¼^M
\ISMVI[KQMV\QÅKIVL_MTTKWV[QLMZMLIXXZWIKP<PMZM[]T\Q[N]VVaQZZM^MZMV\\WXQKITQV\MZIK\Q^MIVL
JZQTTQIV\:MILQVO\PQ[JWWSQ[TQSM[Q\\QVOQV\PM[XMISMZ[TW]VOMI\I^QM_KWVNMZMVKMTMIZVQVONZWU
·IVLTI]OPQVO_Q\P·XMMZ[1N aW]_IV\\W=6,-:;<)6,2I^IOWJ]a\PQ[JWWSº
 ¸)VLZM_8WTTIKS___\PMVWZ\PKWU
¹1N aW]_IV\\WTMIZV2I^ITWWSVWN]Z\PMZ"_MTKWUM\W\PMÅZ[\/=1JI[ML\MKPVQKITJWWS<PQ[XMZNMK\Ta
M`MK]\MLOZW]VLJZMISQVONWZUI\LMTQ^MZ[JMVMÅ\[W\PMZ2I^I\M`\[[QUXTaKIV¼\8ZMXIZMaW]Z[MTN NWZI
\Z]TaZMUIZSIJTMZQLM\PZW]OP2I^ITIVLº
 ¸6MQT:*I]UIV+IX\IQV+-7/MMS+Z]Q[M[___/MMS+Z]Q[M[KWU
?PI\INIV\I[\QK_Ia\WTMIZV1+)667<8=<<01;*773,7?65aaMIZWTL_WSM]XI\
"IU\PQ[UWZVQVOIVL1X]\PQUJIKS\WJML_Q\PJWWSQVPIVLIVLIÆI[PTQOP\[W1KW]TLKWV\QV]M
\WZMILNWZIJW]\IVW\PMZPW]Z
 ¸:W[[/WTLJMZO
¹<PQ[[\]NN Q[[WNZQKSQVOOWWLQ\UISM[UM_IVVI? 81¼U[\]VVMLº
 ¸.TWaL2WVM[;MVQWZ<MKPVQKIT?ZQ\MZ8WWTJWa*-)
Head First Design Patterns Page 5 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
Other related books from O’Reilly
$QW7KH'H¿QLWLYH*XLGH
%HWWHU)DVWHU/LJKWHU-DYD
(QWHUSULVH-DYD%HDQV
+LEHUQDWH$'HYHORSHU¶V1RWHERRN
-DYD7LJHU$'HYHORSHU¶V1RWHERRN

-DYD&RRNERRN
-DYDLQD1XWVKHOO
-DYD1HWZRUN3URJUDPPLQJ
-DYD6HUYOHW-63&RRNERRN
-DYD6ZLQJ
-DYD6HUYHU)DFHV
-DYD6HUYHU3DJHV
3URJUDPPLQJ-DNDUWD6WUXWV
7RPFDW7KH'HILQLWLYH*XLGH
Other books in O’Reilly’s Head First series
+HDG)LUVW-DYD
+HDG)LUVW2EMHFW2ULHQWHG$QDO\VLVDQG'HVLJQ22$'
+HDG5XVK$MD[
+HDG)LUVW+70/ZLWK&66DQG;+70/
+HDG)LUVW'HVLJQ3DWWHUQV
+HDG)LUVW(-%
+HDG)LUVW303
+HDG)LUVW64/
+HDG)LUVW6RIWZDUH'HYHORSPHQW
+HDG)LUVW&
+HDG)LUVW-DYD6FULSW
+HDG)LUVW3URJUDPPLQJ
+HDG)LUVW$MD[
+HDG)LUVW3K\VLFV
+HDG)LUVW6WDWLVWLFV
+HDG)LUVW5XE\RQ5DLOV
+HDG)LUVW3+30\64/
Head First Design Patterns Page 6 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson

ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
YLLL
)]\PWZ[,M^MTWXMZ[WN0MIL.QZ[\,M[QOV8I\\MZV[
WKHDXWKRUV
-ZQKQ[IKWUX]\MZ[KQMV\Q[\_Q\PIXI[[QWVNWZUMLQIIVL
[WN\_IZMIZKPQ\MK\]ZM[0MR][\_ZIXXML]XNW]ZaMIZ[I\
ILZMIURWJ·LQZMK\QVO1V\MZVM\JZWILJIVLIVL_QZMTM[[
MNNWZ\[I\,Q[VMa·IVLQ[VW_JIKS\W_ZQ\QVOKZMI\QVOKWWT
[WN\_IZMIVLPIKSQVO2I^IIVL5IK[
-ZQK[XMV\ITW\WN \PM»![_WZSQVOWVIT\MZVI\Q^M[\W\PM
LM[S\WXUM\IXPWZ_Q\P,I^QL/MTMZV\MZIVL\PMa¼ZM
JW\P[\QTTI[SQVO\PMY]M[\QWV¹_PaLW1PI^M\WOQ^MIÅTM
IVIUM'º*I[MLWV\PQ[_WZS-ZQKTIVLMLI8P,I\
AITM=VQ^MZ[Q\aQV»!0MIT[WKWNW]VLML5QZZWZ?WZTL[
<MKPVWTWOQM[VW_IKY]QZML\WKZMI\MIKWUUMZKQIT
^MZ[QWVWN PQ[\PM[Q[_WZS4QNM[\ZMIU[
1VIXZM^QW][TQNM-ZQKJ]QT\[WN\_IZMNWZVM\_WZS[IVL
[]XMZKWUX]\MZ[AW]UQOP\SVW_PQUNZWU[]KPJWWS[I[
2I^I;XIKM[8ZQVKQXTM[8I\\MZV[IVL8ZIK\QKM-ZQKPI[NWVL
UMUWZQM[WN QUXTMUMV\QVO\]XTM[XIKM[a[\MU[WV
<PQVSQVO5IKPQVM+5[IVLKZMI\QVO[WUMWN \PMÅZ[\
1V\MZVM\QVNWZUI\QWV[a[\MU[NWZ6);)QV\PMTI\M [
-ZQKQ[K]ZZMV\TaTQ^QVOQV\PMPQOPLM[MZ\VMIZ;IV\I
.M?PMVPM¼[V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Z[QXXQVO[WUM2I^IWZ+WKWI
WVPMZ5IKIT\PW]OP[PMLZMIU[WN ILIa_PMV\PM
_PWTM_WZTLQ[][QVO;KPMUM
-TQ[IJM\PPI[TW^MLPQSQVOIVL\PMW]\LWWZ[[QVKMPMZ
LIa[OZW_QVO]XQV;KW\TIVL?PMV[PM¼[W]\LWWZ[
PMZKIUMZIQ[VM^MZNIZ;PM¼[IT[WIVI^QLKaKTQ[\
^MOM\IZQIVIVLIVQUITTW^MZ
AW]KIV[MVLPMZMUIQTI\JM\P(_QKSMLTa[UIZ\KWU

(OLVDEHWK)UHHPDQ
(ULF)UHHPDQ
Head First Design Patterns Page 7 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
+ZMI\WZ[WN\PM0MIL.QZ[\[MZQM[
IVLKWKWV[XQZI\WZ[WV\PQ[JWWS
.DWK\6LHUUD
3I\PaPI[JMMVQV\MZM[\MLQVTMIZVQVO\PMWZa[QVKM
PMZLIa[I[IOIUMLM[QOVMZ[PM_ZW\MOIUM[NWZ>QZOQV
5/5IVL)UJTQV¼;PMLM^MTWXMLU]KPWN \PM0MIL
.QZ[\NWZUI\_PQTM\MIKPQVO6M_5MLQI)]\PWZQVONWZ
=+4)-`\MV[QWV¼[-V\MZ\IQVUMV\;\]LQM[XZWOZIU
5WZMZMKMV\Ta[PM¼[JMMVIUI[\MZ\ZIQVMZNWZ;]V
5QKZW[a[\MU[\MIKPQVO;]V¼[2I^IQV[\Z]K\WZ[PW_\W
\MIKP\PMTI\M[\2I^I\MK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ZWILKI[\KTQMV\[TQSM
:ILQW6M_BMITIVL\PM?MI\PMZ+PIVVMTIVL\PM
)Z\[-V\MZ\IQVUMV\6M\_WZS)-7VMWN PQ[
ITT\QUMNI^WZQ\MXZWRMK\[_I[J]QTLQVOIN]TTZIQT[a[\MU
[QU]TI\QWVNWZ=VQWV8IKQÅK:IQTZWIL
*MZ\Q[ITWVO\QUMPWXMTM[[TaILLQK\ML
OWXTIaMZIVL
PI[JMMV_WZSQVOWVIOWXZWOZIUNWZ_Ia\WWTWVO
0M¼[INIQZO]Q\IZXTIaMZIVLQ[VW_\ZaQVOPQ[PIVLI\
JIVRW
4WWSNWZPQUWVRI^IZIVKPWV\PM1/;OW[MZ^MZWZ
aW]KIV_ZQ\M\WPQUI\\MZZIXQV(_QKSMLTa[UIZ\KWU
%HUW%DWHV
Head First Design Patterns Page 8 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson

ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
[[Y
,QWUR
how to use this book
,FDQ·WEHOLHYHWKH\
SXW
WKDW
LQDGHVLJQ
SDWWHUQVERRN
,QWKLVVHFWLRQZHDQVZHUWKHEXUQLQJTXHVWLRQ
´6RZK\','WKH\SXWWKDWLQDGHVLJQSDWWHUQVERRN"µ
Head First Design Patterns Page 9 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
KRZWRXVHWKLVERRN
[[YL
LQWUR
?PWQ[\PQ[JWWSNWZ'


'R\RXNQRZ-DYD"<RXGRQ¶WQHHGWREHDJXUX

'R\RXZDQWWROHDUQXQGHUVWDQGUHPHPEHUDQG
DSSO\
GHVLJQSDWWHUQVLQFOXGLQJWKH22GHVLJQ
SULQFLSOHVXSRQZKLFKGHVLJQSDWWHUQVDUHEDVHG"
\PQ[JWWSQ[NWZaW]
?PW[PW]TLXZWJIJTaJIKSI_IaNZWU\PQ[JWWS'

$UH\RXFRPSOHWHO\QHZWR-DYD"
<RXGRQ¶WQHHGWREHDGYDQFHGDQGHYHQLI\RX
GRQ¶WNQRZ-DYDEXW\RXNQRZ&\RX¶OOSUREDEO\
XQGHUVWDQGDWOHDVWRIWKHFRGHH[DPSOHV<RX
DOVRPLJKWEHRND\ZLWKMXVWD&EDFNJURXQG

\PQ[JWWSQ[VW\NWZaW]
$UH\RXDIUDLGWRWU\VRPHWKLQJGLIIHUHQW"
:RXOG\RXUDWKHUKDYHDURRWFDQDOWKDQPL[
VWULSHVZLWKSODLG"'R\RXEHOLHYHWKDWDWHFKQLFDO
ERRNFDQ¶WEHVHULRXVLI-DYDFRPSRQHQWVDUH
DQWKURSRPRUSKL]HG"
1N aW]KIVIV[_MZ¹aM[º\WITTWN \PM[M"
1N aW]KIVIV[_MZ¹aM[º\WIVaWVMWN \PM[M"

$UH\RXDNLFNEXWW22GHVLJQHUGHYHORSHUORRNLQJ
IRUD
UHIHUHQFH
ERRN"
>QRWHIURPPDUNHWLQJWKLVERRNLV
IRUDQ\RQHZLWKDFUHGLWFDUG@


'R\RXSUHIHUVWLPXODWLQJGLQQHUSDUW\FRQYHUVDWLRQ
WRGU\GXOODFDGHPLFOHFWXUHV"

$UH\RXDQDUFKLWHFWORRNLQJIRUHQWHUSULVHGHVLJQ
SDWWHUQV"
<RX·OOSUREDEO\EHRND\LI
\RXNQRZ&LQVWHDG
Head First Design Patterns Page 10 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
Licensed by
Zheng Yuan
WKHLQWUR
\RXDUHKHUH
[[YLL
¹0W_KIV\PQ[JMI[MZQW][XZWOZIUUQVOJWWS'º
¹?PI\¼[_Q\PITT\PMOZIXPQK['º
¹+IV1IK\]ITTaTMIZVQ\\PQ[_Ia'º
?MSVW__PI\aW]¼ZM\PQVSQVO
AW]ZJZIQVKZI^M[VW^MT\a1\¼[IT_Ia[[MIZKPQVO[KIVVQVO_IQ\QVONWZ
[WUM\PQVO]V][]IT1\_I[J]QT\\PI\_IaIVLQ\PMTX[aW][\IaITQ^M
<WLIaaW]¼ZMTM[[TQSMTa\WJMI\QOMZ[VIKS*]\aW]ZJZIQV¼[[\QTTTWWSQVOAW]
R][\VM^MZSVW_

;W_PI\LWM[aW]ZJZIQVLW_Q\PITT\PMZW]\QVMWZLQVIZaVWZUIT\PQVO[
aW]MVKW]V\MZ'-^MZa\PQVOQ\KIV\W[\WX\PMUNZWUQV\MZNMZQVO_Q\P\PM
JZIQV¼[ZMITRWJ¸ZMKWZLQVO\PQVO[\PI\UI\\MZ1\LWM[V¼\JW\PMZ[I^QVO
\PMJWZQVO\PQVO[#\PMaVM^MZUISMQ\XI[\\PM¹\PQ[Q[WJ^QW][TaVW\
QUXWZ\IV\ºÅT\MZ
0W_LWM[aW]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
Head First Design Patterns Page 11 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
KRZWRXVHWKLVERRN
[[YLLL
LQWUR
6RZKDWGRHVLWWDNHWR
OHDUQ
VRPHWKLQJ")LUVW\RXKDYHWR
JHW
LWWKHQPDNHVXUH
\RXGRQ·W
IRUJHW
LW,W·VQRWDERXWSXVKLQJIDFWVLQWR\RXUKHDG%DVHGRQWKH
ODWHVWUHVHDUFKLQFRJQLWLYHVFLHQFHQHXURELRORJ\DQGHGXFDWLRQDOSV\FKRORJ\
OHDUQLQJ
WDNHVDORWPRUHWKDQWH[WRQDSDJH:HNQRZZKDWWXUQV\RXUEUDLQRQ
6RPHRIWKH+HDG)LUVWOHDUQLQJSULQFLSOHV
0DNHLWYLVXDO)MAGESAREFARMOREMEMORABLETHANWORDSALONEAND
MAKELEARNINGMUCHMOREEFFECTIVEUPTOIMPROVEMENTINRECALLAND

TRANSFERSTUDIES)TALSOMAKESTHINGSMOREUNDERSTANDABLE3XWWKH
ZRUGVZLWKLQRUQHDUWKHJUDSKLFVTHEYRELATETORATHERTHANON
THEBOTTOMORONANOTHERPAGEANDLEARNERSWILLBEUPTOTWICEASLIKELY
TOSOLVEPROBLEMSRELATEDTOTHECONTENT
8VHDFRQYHUVDWLRQDODQGSHUVRQDOL]HGVW\OH)NRECENTSTUDIESSTUDENTS
PERFORMEDUPTOBETTERONPOSTLEARNINGTESTSIFTHECONTENTSPOKEDIRECTLYTO
THEREADERUSINGAFIRSTPERSONCONVERSATIONALSTYLERATHERTHANTAKINGAFORMAL
TONE4ELLSTORIESINSTEADOFLECTURING5SECASUALLANGUAGE$ONTTAKEYOURSELF
TOOSERIOUSLY7HICHWOULDYOUPAYMOREATTENTIONTOASTIMULATINGDINNERPARTY
COMPANIONORALECTURE
*HWWKHOHDUQHUWRWKLQNPRUHGHHSO\)NOTHERWORDSUNLESS
YOUACTIVELYFLEXYOURNEURONSNOTHINGMUCHHAPPENSINYOURHEAD
!READERHASTOBEMOTIVATEDENGAGEDCURIOUSANDINSPIREDTO
SOLVEPROBLEMSDRAWCONCLUSIONSANDGENERATENEWKNOWLEDGE
!NDFORTHATYOUNEEDCHALLENGESEXERCISESANDTHOUGHTPROVOKING
QUESTIONSANDACTIVITIESTHATINVOLVEBOTHSIDESOFTHEBRAIN
ANDMULTIPLESENSES
*HW³DQGNHHS³WKHUHDGHU·VDWWHQWLRQ7EVE
ALLHADTHEh)REALLYWANTTOLEARNTHISBUT)CANTSTAYAWAKEPAST
PAGEONEvEXPERIENCE9OURBRAINPAYSATTENTIONTOTHINGSTHAT
AREOUTOFTHEORDINARYINTERESTINGSTRANGEEYECATCHINGUNEXPECTED
,EARNINGANEWTOUGHTECHNICALTOPICDOESNTHAVETOBEBORING9OURBRAINWILL
LEARNMUCHMOREQUICKLYIFITSNOT
7RXFKWKHLUHPRWLRQV7ENOWKNOWTHATYOURABILITYTOREMEMBERSOMETHINGISLARGELY
DEPENDENTONITSEMOTIONALCONTENT9OUREMEMBERWHATYOUCAREABOUT9OUREMEMBERWHEN
YOUFEELSOMETHING.OWERENOTTALKINGHEARTWRENCHINGSTORIESABOUTABOYANDHISDOG
7ERETALKINGEMOTIONSLIKESURPRISECURIOSITYFUNhWHATTHEvANDTHEFEELINGOFh)2ULEv
THATCOMESWHENYOUSOLVEAPUZZLELEARNSOMETHINGEVERYBODYELSETHINKSISHARDORREALIZE
YOUKNOWSOMETHINGTHATh)MMORETECHNICALTHANTHOUv"OBFROMENGINEERINGDOESNT
:HWKLQNRID´+HDG)LUVWµUHDGHUDVDOHDUQHU

GR&DOF
UHWXUQYDOXH
QHHGVWRFDOOD
PHWKRGRQWKH
VHUYHU
50,UHPRWH
VHUYLFH
,WUHDOO\VXFNVWREHDQ
DEVWUDFWPHWKRG<RX
GRQ·WKDYHDERG\
DEVWUDFWYRLGURDP
1RPHWKRGERG\
(QGLWZLWKDVHPLFRORQ
'RHVLWPDNHVHQVHWR
VD\7XE,6$%DWKURRP"
%DWKURRP,6$7XE"2ULV
LWD+$6$UHODWLRQVKLS"
Head First Design Patterns Page 12 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
WKHLQWUR
\RXDUHKHUH
[[L[
1N aW]ZMITTa_IV\\WTMIZVIVLaW]_IV\\WTMIZVUWZMY]QKSTaIVLUWZMLMMXTa

XIaI\\MV\QWV\WPW_aW]XIaI\\MV\QWV<PQVSIJW]\PW_aW]\PQVS4MIZVPW_aW]
TMIZV
5W[\WN ][LQLVW\\ISMKW]Z[M[WVUM\IKWOVQ\QWVWZTMIZVQVO\PMWZa_PMV_M_MZM
OZW_QVO]X?M_MZMM`XMK\ML\WTMIZVJ]\ZIZMTa\I]OP\\WTMIZV
*]\_MI[[]UM\PI\QN aW]¼ZMPWTLQVO\PQ[JWWSaW]ZMITTa_IV\\WTMIZVLM[QOV
XI\\MZV[)VLaW]XZWJIJTaLWV¼\_IV\\W[XMVLITW\WN \QUM)VLaW]_IV\
\WZMUMUJMZ_PI\aW]ZMILIVLJMIJTM\WIXXTaQ\)VLNWZ\PI\aW]¼^MOW\\W
]VLMZ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MJMMVXZW^MV\WPMTXaW]ZJZIQV_WZSQVaW]ZNI^WZ.WZ

M`IUXTM[\]LQM[[PW_\PI\X]\\QVO_WZL[_Q\PQV\PMXQK\]ZM[\PMaLM[KZQJMI[WXXW[ML\W
[WUM_PMZMMT[MQV\PMXIOMTQSMIKIX\QWVWZQV\PMJWLa\M`\KI][M[aW]ZJZIQV\W\Za\W
UISM[[MV[MWN PW_\PM_WZL[IVLXQK\]ZMZMTI\MIVL\PQ[KI][M[UWZMVM]ZWV[\WÅZM
5WZMVM]ZWV[ÅZQVO%UWZMKPIVKM[NWZaW]ZJZIQV\WOM\\PI\\PQ[Q[[WUM\PQVO_WZ\P
XIaQVOI\\MV\QWV\WIVLXW[[QJTaZMKWZLQVO
)KWV^MZ[I\QWVIT[\aTMPMTX[JMKI][MXMWXTM\MVL\WXIaUWZMI\\MV\QWV_PMV\PMa
XMZKMQ^M\PI\\PMa¼ZMQVIKWV^MZ[I\QWV[QVKM\PMa¼ZMM`XMK\ML\WNWTTW_ITWVOIVLPWTL]X
\PMQZMVL<PMIUIbQVO\PQVOQ[aW]ZJZIQVLWM[V¼\VMKM[[IZQTaKIZM\PI\\PM¹KWV^MZ[I\QWVº
Q[JM\_MMVaW]IVLIJWWS7V\PMW\PMZPIVLQN \PM_ZQ\QVO[\aTMQ[NWZUITIVLLZaaW]Z
JZIQVXMZKMQ^M[Q\\PM[IUM_IaaW]M`XMZQMVKMJMQVOTMK\]ZML\W_PQTM[Q\\QVOQVIZWWUN]T
WN XI[[Q^MI\\MVLMM[6WVMML\W[\IaI_ISM
*]\XQK\]ZM[IVLKWV^MZ[I\QWVIT[\aTMIZMR][\\PMJMOQVVQVO
Head First Design Patterns Page 13 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
KRZWRXVHWKLVERRN
[[[
LQWUR
?M][MLXQK\]ZM[JMKI][MaW]ZJZIQVQ[\]VMLNWZ^Q[]IT[VW\\M`\)[NIZI[aW]ZJZIQV¼[
KWVKMZVMLIXQK\]ZMZMITTaQ[_WZ\P_WZL[)VL_PMV\M`\IVLXQK\]ZM[_WZS\WOM\PMZ_M
MUJMLLML\PM\M`\QV\PMXQK\]ZM[JMKI][MaW]ZJZIQV_WZS[UWZMMNNMK\Q^MTa_PMV\PM\M`\Q[
_Q\PQV\PM\PQVO\PM\M`\ZMNMZ[\WI[WXXW[ML\WQVIKIX\QWVWZJ]ZQMLQV\PM\M`\[WUM_PMZM
?M][MLZML]VLIVKa[IaQVO\PM[IUM\PQVOQVLQNNMZMV\_Ia[IVL_Q\PLQNNMZMV\UMLQI\aXM[
IVLU]T\QXTM[MV[M[\WQVKZMI[M\PMKPIVKM\PI\\PMKWV\MV\OM\[KWLMLQV\WUWZM\PIVWVMIZMIWN 

aW]ZJZIQV
?M][MLKWVKMX\[IVLXQK\]ZM[QV]VM`XMK\ML_Ia[JMKI][MaW]ZJZIQVQ[\]VMLNWZVW^MT\a
IVL_M][MLXQK\]ZM[IVLQLMI[_Q\PI\TMI[\[WUMMUW\QWVITKWV\MV\JMKI][MaW]ZJZIQVQ[
\]VML\WXIaI\\MV\QWV\W\PMJQWKPMUQ[\ZaWN MUW\QWV[<PI\_PQKPKI][M[aW]\WNMMT[WUM\PQVO
Q[UWZMTQSMTa\WJMZMUMUJMZMLM^MVQN \PI\NMMTQVOQ[VW\PQVOUWZM\PIVITQ\\TMP]UWZ
[]ZXZQ[MWZQV\MZM[\
?M][MLIXMZ[WVITQbMLKWV^MZ[I\QWVIT[\aTMJMKI][MaW]ZJZIQVQ[\]VML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First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608

© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.
WKHLQWUR
\RXDUHKHUH
[[[L
;W_MLQLW]ZXIZ\<PMZM[\Q[]X\WaW]<PM[M\QX[IZMI
[\IZ\QVOXWQV\#TQ[\MV\WaW]ZJZIQVIVLÅO]ZMW]\_PI\_WZS[
NWZaW]IVL_PI\LWM[V¼\<ZaVM_\PQVO[
0MZM¼[_PI\A7=KIVLW\WJMVL
aW]ZJZIQVQV\W[]JUQ[[QWV

6ORZGRZQ7KHPRUH\RXXQGHUVWDQG
WKHOHVV\RXKDYHWRPHPRUL]H
,WV¼\R][\ZMIL;\WXIVL\PQVS?PMV\PM
JWWSI[S[aW]IY]M[\QWVLWV¼\R][\[SQX\W\PM
IV[_MZ1UIOQVM\PI\[WUMWVMZMITTaQ[I[SQVO
\PMY]M[\QWV<PMUWZMLMMXTaaW]NWZKMaW]Z
JZIQV\W\PQVS\PMJM\\MZKPIVKMaW]PI^MWN 
TMIZVQVOIVLZMUMUJMZQVO

'RWKHH[HUFLVHV:ULWH\RXURZQQRWHV
?MX]\\PMUQVJ]\QN _MLQL\PMUNWZaW]
\PI\_W]TLJMTQSMPI^QVO[WUMWVMMT[MLW
aW]Z_WZSW]\[NWZaW])VLLWV¼\R][\TWWSI\
\PMM`MZKQ[M[=[MIXMVKQT<PMZM¼[XTMV\aWN 
M^QLMVKM\PI\XPa[QKITIK\Q^Q\a
_PQTM
TMIZVQVO
KIVQVKZMI[M\PMTMIZVQVO


5HDGWKH´7KHUHDUH1R'XPE4XHVWLRQVµ
<PI\U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[\MZJa\ZaQVO\W[PW^MUWZMQVIVLaW]
UQOP\M^MVP]Z\\PMXZWKM[[

'HVLJQ
VRPHWKLQJ
)XXTa\PQ[\W[WUM\PQVOVM_aW]¼ZMLM[QOVQVOWZ
ZMNIK\WZIVWTLMZXZWRMK\2][\LW[WUM\PQVO\WOM\
[WUMM`XMZQMVKMJMaWVL\PMM`MZKQ[M[IVLIK\Q^Q\QM[
QV\PQ[JWWS)TTaW]VMMLQ[IXMVKQTIVLIXZWJTMU
\W[WT^MIXZWJTMU\PI\UQOP\JMVMÅ\NZWUWVMWZ
UWZMLM[QOVXI\\MZV[
FXWWKLVRXWDQGVWLFNLW
RQ\RXUUHIULGJHUDWRU

)HHO
VRPHWKLQJ
AW]ZJZIQVVMML[\WSVW_\PI\\PQ[UI\\MZ[/M\
QV^WT^ML_Q\P\PM[\WZQM[5ISM]XaW]ZW_VKIX
\QWV[NWZ\PMXPW\W[/ZWIVQVOW^MZIJILRWSMQ[[\QTT
JM\\MZ\PIVNMMTQVOVW\PQVOI\ITT
Head First Design Patterns Page 15 Return to Table of Contents
Head First Design Patterns
Head First Design Patterns By Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson

ISBN: 0596007124 Publisher: O'Reilly Media, Inc.
Prepared for Zheng Yuan, Safari ID:
Licensed by Zheng Yuan
Print Publication Date: 2004/10/25 User number: 1862608
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
requires prior written consent from the copyright owner. Unauthorized use, reproduction and/or distribution are strictly prohibited and violate applicable laws. All rights reserved.

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×