本書可以讓讀者在親手實踐中深刻領會并全面掌握Java軟件項目中設計模式的巨大力量。本書采取學用結合的實用手冊形式,帶領讀者應用Java的最新特性,實踐23種原始模式的最佳做法。.Steve Metsker 和 Bill Wake憑借豐富的Java教學和編程經驗,在講解每一個模式時都輔以真實的Java程序、清晰的UML圖表和趣味盎然的練習,使讀者可以很快從理論過渡到實踐――學會如何改進新的代碼和重構已有代碼,使其簡潔、可管理且性能優(yōu)良。..如果您是Java程序員,既想節(jié)省時間,又想寫出更好的代碼,本書中的技術、技巧、清晰的講解、明快的示例會幫助您駕馭模式的力量,改進您所寫、所設計、所維護的每一個程序。本書適合有一定基礎,需要節(jié)省時間并改善代碼性能的Java程序員。...
作者簡介
本書提供作譯者介紹Steven John Metsker 在設計模式、面向對象程序設計方法學等領域有廣泛的著述,致力于研究編寫結構清晰功能強大的軟件,在《Java Report》、《JOOP》、《Distributed Object Computing》和《Object Magazine》等雜志上發(fā)表了多篇著作。.William C. Wake是一位自由軟件顧問、指導和訓練師,有二十多年的編程經驗,著有《Refactoring Workbook》和《Extreme Programming Explored》等著作。...
圖書目錄
CHAPTER 1 INTRODUCTION 1 Why Patterns? 1 Why Design Patterns? 2 Why Java? 3 UML 4 Challenges 4 The Organization of This Book 5 Welcome to Oozinoz! 6 Summary 7 PART I INTERFACE PATTERNS 9 CHAPTER 2 INTRODUCING INTERFACES 11 Interfaces and Abstract Classes 11 Interfaces and Obligations 13 Summary 15 Beyond Ordinary Interfaces 16 CHAPTER 3 ADAPTER 17 Adapting to an Interface 17 Class and Object Adapters 21 Adapting Data for a Jtable 25 Identifying Adapters 30 Summary 31 CHAPTER 4 FA?ADE 33 Facades, Utilities, and Demos 33 Refactoring to FACADE 35 Summary 46 CHAPTER 5 COMPOSITE 47 An Ordinary Composite 47 Recursive Behavior in Composites 48 Composites, Trees, and Cycles 50 Composites with Cycles 56 Consequences of Cycles 60 Summary 60 CHAPTER 6 BRIDGE 63 An Ordinary Abstraction: On the Way to BRIDGE 63 From Abstraction to BRIDGE 66 Drivers as BRIDGEs 68 Database Drivers 69 Summary 71 PART II RESPONSIBILITY PATTERNS 73 CHAPTER 7 INTRODUCING RESPONSIBILITY 75 Ordinary Responsibility 75 Controlling Responsibility with Visibility 77 Summary 79 Beyond Ordinary Responsibility 79 CHAPTER 8 SINGLETON 81 SINGLETON Mechanics 81 Singletons and Threads 83 Recognizing SINGLETON 84 Summary 86 CHAPTER 9 OBSERVER 87 A Classic Example: OBSERVER in GUIs 87 Model/View/Controller 92 Maintaining an Observable Object 99 Summary 101 CHAPTER 10 MEDIATOR 103 A Classic Example: GUI Mediators 103 Mediators of Relational Integrity 108 Summary 116 CHAPTER 11 PROXY 117 A Classic Example: Image Proxies 117 Image Proxies Reconsidered 122 Remote Proxies 125 Dynamic Proxies 131 Summary 136 CHAPTER 12 CHAIN OF RESPONSIBILITY 137 An Ordinary Chain of Responsibility 137 Refactoring to CHAIN OF RESPONSIBILITY 139 Anchoring a Chain 142 CHAIN OF RESPONSIBILITY without COMPOSITE 144 Summary 144 CHAPTER 13 FLYWEIGHT 145 Immutability 145 Extracting the Immutable Part of a Flyweight 146 Sharing Flyweights 148 Summary 152 PART III CONSTRUCTION PATTERNS 153 CHAPTER 14 INTRODUCING CONSTRUCTION 155 A Few Construction Challenges 155 Summary 157 Beyond Ordinary Construction 157 CHAPTER 15 BUILDER 159 An Ordinary Builder 159 Building under Constraints 162 A Forgiving Builder 164 Summary 165 CHAPTER 16 FACTORY METHOD 167 A Classic Example: Iterators 167 Recognizing FACTORY METHOD 168 Taking Control of Which Class to Instantiate 169 FACTORY METHOD in Parallel Hierarchies 171 Summary 173 CHAPTER 17 ABSTRACT FACTORY 175 A Classic Example: GUI Kits 175 Abstract Factories and Factory Method 180 Packages and Abstract Factories 184 Summary 185 CHAPTER 18 PROTOTYPE 187 Prototypes as Factories 187 Prototyping with Clones 189 Summary 192 CHAPTER 19 MEMENTO 193 A Classic Example: Using Memento for Undo 193 Memento Durability 201 Persisting Mementos Across Sessions 201 Summary 205 PART IV OPERATION PATTERNS 207 CHAPTER 20 INTRODUCING OPERATIONS 209 Operations and Methods 209 Signatures 211 Exceptions 212 Algorithms and Polymorphism 213 Summary 214 Beyond Ordinary Operations 215 CHAPTER 21 TEMPLATE METHOD 217 A Classic Example: Sorting 217 Completing an Algorithm 221 TEMPLATE METHOD Hooks 224 Refactoring to TEMPLATE METHOD 225 Summary 228 CHAPTER 22 STATE 229 Modeling States 229 Refactoring to STATE 233 Making States Constant 238 Summary 240 CHAPTER 23 STRATEGY 241 Modeling Strategies 241 Refactoring to STRATEGY 244 Comparing STRATEGY and STATE 248 Comparing STRATEGY and TEMPLATE Method 249 Summary 250 CHAPTER 24 COMMAND 251 A Classic Example: Menu Commands 251 Using COMMAND to Supply a Service 254 COMMAND Hooks 255 COMMAND in Relation to Other Patterns 257 Summary 259 CHAPTER 25 INTERPRETER 261 An INTERPRETER Example 261 Interpreters, Languages, and Parsers 274 Summary 275 PART V EXTENSION PATTERNS 277 CHAPTER 26 INTRODUCING EXTENSIONS 279 Principles of Object-Oriented Design 279 The Liskov Substitution Principle 280 The Law of Demeter 281 Removing Code Smells 283 Beyond Ordinary Extensions 283 Summary 285 CHAPTER 27 DECORATOR 287 A Classic Example: Streams and Writers 287 Function Wrappers 295 DECORATOR in Relation to Other Patterns 303 Summary 303 CHAPTER 28 ITERATOR 305 Ordinary Iteration 305 Thread-Safe Iteration 307 Iterating over a Composite 313 Summary 324 CHAPTER 29 VISITOR 325 VISITOR Mechanics 325 An Ordinary VISITOR 327 VISITOR Cycles 333 VISITOR Risks 338 Summary 340 PART VI APPENDIXES 341 APPENDIX A DIRECTIONS 343 Get the Most from This Book 343 Understand the Classics 344 Weave Patterns into Your Code 344 Keep Learning 345 APPENDIX B SOLUTIONS 347 APPENDIX C OOZINOZ SOURCE 427 Acquiring and Using the Source 427 Building the Oozinoz Code 427 Testing the Code with JUnit 428 Finding Files Yourself 428 Summary 429 APPENDIX D UML AT A GLANCE 431 Classes 432 Class Relationships 433 Interfaces 435 Objects 436 States 437 Glossary 439 Bibliography 447 Index 449