tailieunhanh - THE DESIGN PATTERNS JAVA COMPANION

The term “design patterns” sounds a bit formal to the uninitiated and can be somewhat off-putting when you first encounter it. But, in fact, design patterns are just convenient ways of reusing object-oriented code between projects and between programmers. The idea behind design patterns is simple-- write down and catalog common interactions between objects that programmers have frequently found useful. | 1 2 The Design Patterns Java Companion James W. Cooper October 2 1998 Addison-Wesley Design Patterns Series Copyright 1998 by James W. Cooper 3 Some Background on Design Patterns 10 Defining Design Patterns 11 This Book and its Parentage 13 The Learning Process 13 Studying Design Patterns 14 Notes on Object Oriented Approaches 14 The Java Foundation Classes 15 Java Design Patterns 15 1. Creational Patterns 17 The Factory Pattern 18 How a Factory Works 18 Sample Code 18 The Two Derived Classes 19 Building the Factory 20 Factory Patterns in Math Computation 22 When to Use a Factory Pattern 24 Thought Questions 25 The Abstract Factory Pattern 26 A GardenMaker Factory 26 How the User Interface Works 28 Consequences of Abstract Factory 30 Thought Questions 30 The Singleton Pattern 31 Throwing the Exception 32 Creating an Instance of the Class 32 Static Classes as Singleton Patterns 33 Creating Singleton Using a Static Method .