Java

Solo disponible en BuenasTareas
  • Páginas : 64 (15760 palabras )
  • Descarga(s) : 0
  • Publicado : 2 de marzo de 2012
Leer documento completo
Vista previa del texto
1

2

THE

DESIGN PATTERNS
JAVA COMPANION

JAMES W. COOPER

October 2, 1998 Copyright © 1998, by James W. Cooper

3

Some Background on Design Patterns
Defining Design Patterns This Book and its Parentage The Learning Process Studying Design Patterns Notes on Object Oriented Approaches The Java Foundation Classes Java Design Patterns

10
11 13 13 14 14 15 15

1. CreationalPatterns

17 18
18 18 19 20 22 24 25

The Factory Pattern
How a Factory Works Sample Code The Two Derived Classes Building the Factory Factory Patterns in Math Computation When to Use a Factory Pattern Thought Questions

The Abstract Factory Pattern
A GardenMaker Factory How the User Interface Works Consequences of Abstract Factory Thought Questions

26
26 28 30 30

The SingletonPattern
Throwing the Exception Creating an Instance of the Class Static Classes as Singleton Patterns Creating Singleton Using a Static Method

31
32 32 33 34

4

Finding the Singletons in a Large Program Other Consequences of the Singleton Pattern

35 35

The Builder Pattern
An Investment Tracker Calling the Builders The List Box Builder The Checkbox Builder Consequences of the BuilderPattern Thought Questions

37
38 40 42 43 44 44

The Prototype Pattern
Cloning in Java Using the Prototype Consequences of the Prototype Pattern

45
45 47 50

Summary of Creational Patterns 2. The Java Foundation Classes
Ideas Behind Swing The Swing Class Hierarchy

51
52 53 53

52

Installing and Using the JFC

Writing a Simple JFC Program
Setting the Look and Feel Settingthe Window Close Box Making a JxFrame Class A Simple Two Button Program More on JButtons

54
54 55 55 56 57

Buttons and Toolbars
Radio Buttons The JToolBar Toggle Buttons

59
59 59 60

5

Sample Code

61

Menus and Actions
Action Objects Design Patterns in the Action Object

62
62 65

The JList Class
List Selections and Events Changing a List Display Dynamically

67
6869

The JTable Class
A Simple JTable Program Cell Renderers

71
71 74

The JTree Class
The TreeModel Interface Summary

77
78 79

3. Structural Patterns

80 81
81 83 87 87 88

The Adapter Pattern
Moving Data between Lists Using the JFC JList Class Two Way Adapters Pluggable Adapters Adapters in Java

The Bridge Pattern
Building a Bridge Consequences of the Bridge Pattern90
91 93

The Composite Pattern
An Implementation of a Composite Building the Employee Tree Restrictions on Employee Classes

95
96 98 100

6

Consequences of the Composite Pattern Other Implementation Issues

100 101

The Decorator Pattern
Decorating a CoolButton Using a Decorator Inheritance Order Decorating Borders in Java Non-Visual Decorators Decorators, Adapters andComposites Consequences of the Decorator Pattern

103
103 105 107 107 109 110 110

The Façade Pattern
Building the Façade Classes Consequences of the Façade

111
112 115

The Flyweight Pattern
Discussion Example Code Flyweight Uses in Java Sharable Objects

117
117 118 122 122

The Proxy Pattern
Sample Code Copy-on-Write Comparison with Related Patterns

124
124 127 127

Summary ofstructural patterns 4. Behavioral Patterns
Applicability Sample Code

128 130
130 131

129

Chain of Responsibility

7

The List Boxes A Chain or a Tree? Kinds of Requests Examples in Java Consequences of the Chain of Responsibility

133 135 137 137 138

The Command Pattern
Motivation The Command Pattern Building Command Objects The Command Pattern in Java Consequences of theCommand Pattern Providing Undo

139
139 140 141 142 143 144

The Interpreter Pattern
Motivation Applicability Sample Code Interpreting the Language Objects Used in Parsing Reducing the Parsed Stack Consequences of the Interpreter Pattern

145
145 145 146 147 148 150 153

The Iterator Pattern
Motivation Enumerations in Java Filtered Iterators Sample Code Consequence of the Iterator...
tracking img