Java Design Patterns A tutorial 2000.pdf
(
4845 KB
)
Pobierz
22954118 UNPDF
Java™ Design Patterns: A Tutorial
Publisher : Addison Wesley
Pub Date : January 28, 2000
ISBN : 0-201-48539-7
Pages : 352
Design patterns have become a staple of object-oriented design and programming by
providing elegant, easy-to-reuse, and maintainable solutions to commonly encountered
programming challenges. However, many busy Java programmers have yet to learn about
design patterns and incorporate this powerful technology into their work.
Java(TM)Design Patterns
is exactly the tutorial resource you need. Gentle and clearly
written, it helps you understand the nature and purpose of design patterns. It also serves
as a practical guide to using design patterns to create sophisticated, robust Java programs.
This book presents the 23 patterns cataloged in the flagship book
Design Patterns
by
Gamma, Helm, Johnson, and Vlissides. In
Java(TM)Design Patterns,
each of these
patterns is illustrated by at least one complete visual Java program. This practical
approach makes design pattern concepts more concrete and easier to grasp, brings Java
programmers up to speed quickly, and enables you to take practical advantage of the
power of design patterns.
Key features include:
•
Introductory overviews of design patterns, the Java Foundation Classes (JFC),
and the Unified Modeling Language (UML)
•
Screen shots of each of the programs
•
UML diagrams illustrating interactions between the classes, along with the
original JVISION diagram files
•
An explanation of the Java Foundation Classes that illustrates numerous design
patterns
•
Case studies demonstrating the usefulness of design patterns in solving Java
programming problems
•
A CD containing all of the examples in the book, so you can run, edit, and
modify the complete working programs
After reading this tutorial, you will be comfortable with the basics of design patterns and
will be able to start using them effectively in your day-to-day Java programming work.
Team-Fly
®
By
James W. Cooper
Table of Content
Table of Content
...........................................................................................................i
Copyright
.............................................................................................................. viii
Credits
..................................................................................................................ix
Preface
.....................................................................................................................ix
About the Author
......................................................................................................x
Acknowledgments
...................................................................................................x
Section 1: What Are Design Patterns?
..................................................................12
Chapter 1. Introduction
.........................................................................................13
Defining Design Patterns
.................................................................................14
The Learning Process
......................................................................................15
Studying Design Patterns
................................................................................16
Notes on Object-Oriented Approaches
..........................................................16
The Java Foundation Classes
.........................................................................17
Java Design Patterns
........................................................................................17
Chapter 2. UML Diagrams
...................................................................................18
Inheritance
..........................................................................................................19
Interfaces
............................................................................................................20
Composition
.......................................................................................................20
Annotation
..........................................................................................................22
JVISION UML Diagrams
..................................................................................22
Visual SlickEdit Project Files
...........................................................................22
Section 2: Creational Patterns
................................................................................24
Chapter 3. The Factory Pattern
..........................................................................25
How a Factory Works
.......................................................................................25
Sample Code
.....................................................................................................25
The Two Subclasses
........................................................................................26
Building the Simple Factory
.............................................................................27
Factory Patterns in Math Computation
..........................................................28
Programs on the CD-ROM
..............................................................................29
Chapter 4. The Factory Method
..........................................................................30
The Swimmer Class
..........................................................................................32
The Event Classes
............................................................................................32
Straight Seeding
................................................................................................33
Our Seeding Program
.......................................................................................35
Other Factories
..................................................................................................35
When to Use a Factory Method
......................................................................35
Programs on the CD-ROM
..............................................................................36
Chapter 5. The Abstract Factory Pattern
...........................................................37
A GardenMaker Factory
...................................................................................37
How the User Interface Works
........................................................................39
Adding More Classes
........................................................................................40
Consequences of the Abstract Factory Pattern
...........................................41
Programs on the CD-ROM
..............................................................................41
Chapter 6. The Singleton pattern
........................................................................42
Creating a Singleton Using a Static Method
.................................................42
Exceptions and Instances
................................................................................43
Throwing an Exception
.....................................................................................43
ii
Creating an Instance of the Class
..................................................................43
Providing a Global Point of Access to a Singleton Pattern
.........................44
The javax.comm Package as a Singleton
.....................................................45
Other Consequences of the Singleton Pattern
.............................................48
Programs on the CD-ROM
..............................................................................48
Chapter 7. The Builder Pattern
...........................................................................50
An Investment Tracker
.....................................................................................50
Calling the Builders
...........................................................................................52
The List Box Builder
..........................................................................................54
The Check Box Builder
.....................................................................................54
Consequences of the Builder Pattern
............................................................56
Programs on the CD-ROM
..............................................................................57
Chapter 8. The Prototype Pattern
.......................................................................58
Cloning in Java
..................................................................................................58
Using the Prototype
..........................................................................................59
Using the Prototype Pattern
............................................................................62
Prototype Managers
..........................................................................................65
Cloning Using Serialization
..............................................................................65
Consequences of the Prototype Pattern
........................................................66
Programs on the CD-ROM
..............................................................................67
Summary of Creational Patterns
.....................................................................68
Section 3: Structural Patterns
..................................................................................69
Chapter 9. The Adapter Pattern
..........................................................................70
Moving Data between Lists
..............................................................................70
Using the JFC JList Class
................................................................................71
Two-Way Adapters
............................................................................................76
Pluggable Adapters
...........................................................................................76
Adapters in Java
................................................................................................77
Programs on the CD-ROM
..............................................................................78
Chapter 10. The Bridge Pattern
..........................................................................80
The Class Diagram
...........................................................................................81
Extending the Bridge
........................................................................................82
Java Beans as Bridges
.....................................................................................84
Consequences of the Bridge Pattern
.............................................................85
Programs on the CD-ROM
..............................................................................85
Chapter 11. The Composite Pattern
..................................................................87
An Implementation of a Composite
................................................................87
Computing Salaries
...........................................................................................88
The Employee Classes
....................................................................................88
The Boss Class
..................................................................................................90
Building the Employee Tree
............................................................................91
Self-Promotion
...................................................................................................93
Doubly Linked List
.............................................................................................94
Consequences of the Composite Pattern
......................................................95
A Simple Composite
.........................................................................................95
Composites in Java
...........................................................................................96
Other Implementation Issues
..........................................................................96
Programs on the CD-ROM
..............................................................................96
Chapter 12. The Decorator Pattern
....................................................................98
Decorating a CoolButton
..................................................................................98
iii
Using a Decorator
.............................................................................................99
The Class Diagram
.........................................................................................101
Decorating Borders in Java
...........................................................................101
Nonvisual Decorators
.....................................................................................103
Decorators, Adapters, and Composites
.......................................................105
Consequences of the Decorator Pattern
.....................................................106
Programs on the CD-ROM
............................................................................106
Chapter 13. The Façade Pattern
......................................................................107
Building the Façade Classes
.........................................................................108
Consequences of the Façade Pattern
.........................................................112
Notes on Installing and Running the dbFrame Program
...........................112
Programs on the CD-ROM
............................................................................113
Chapter 14. The Flyweight Pattern
...................................................................114
Discussion
........................................................................................................115
Example Code
.................................................................................................115
Flyweight Uses in Java
...................................................................................119
Sharable Objects
.............................................................................................120
Copy-on-Write Objects
...................................................................................120
Programs on the CD-ROM
............................................................................120
Chapter 15. The Proxy Pattern
.........................................................................122
Sample Code
...................................................................................................122
Copy-on-Write
..................................................................................................124
Enterprise Java Beans
...................................................................................124
Comparison with Related Patterns
...............................................................125
Programs on the CD-ROM
............................................................................125
Summary of Structural Patterns
....................................................................126
Section 4: Behavioral Patterns
..............................................................................127
Chapter 16. Chain of Responsibility Pattern
...................................................128
Applicability
......................................................................................................129
Sample Code
...................................................................................................129
The List Boxes
.................................................................................................132
Programming a Help System
........................................................................134
A Chain or a Tree?
..........................................................................................137
Kinds of Requests
...........................................................................................139
Examples in Java
............................................................................................139
Consequences of the Chain of Responsibility
............................................139
Programs on the CD-ROM
............................................................................140
Chapter 17. The Command Pattern
.................................................................141
Motivation
.........................................................................................................141
Command Objects
..........................................................................................142
Building Command Objects
...........................................................................143
The Command Pattern
...................................................................................144
The Command Pattern in the Java Language
............................................147
Consequences of the Command Pattern
....................................................147
Providing Undo
................................................................................................148
Programs on the CD-ROM
............................................................................152
Chapter 18. The Interpreter Pattern
.................................................................153
Motivation
.........................................................................................................153
Applicability
......................................................................................................153
Simple Report Example
..................................................................................153
iv
Interpreting the Language
..............................................................................154
Objects Used in Parsing
.................................................................................155
Reducing the Parsed Stack
...........................................................................158
Implementing the Interpreter Pattern
...........................................................159
Consequences of the Interpreter Pattern
....................................................163
Programs on the CD-ROM
............................................................................164
Chapter 19. The Iterator Pattern
.......................................................................165
Motivation
.........................................................................................................165
Enumerations in Java
.....................................................................................165
Sample Code
...................................................................................................166
Filtered Iterators
..............................................................................................167
Consequences of the Iterator Pattern
..........................................................169
Composites and Iterators
...............................................................................170
Iterators in Java 1.2
........................................................................................170
Programs on the CD-ROM
............................................................................171
Chapter 20. The Mediator Pattern
....................................................................172
An Example System
........................................................................................172
Interactions between Controls
.......................................................................173
Sample Code
...................................................................................................174
Mediators and Command Objects
................................................................177
Consequences of the Mediator Pattern
.......................................................178
Single Interface Mediators
.............................................................................178
Implementation Issues
....................................................................................178
Programs on the CD-ROM
............................................................................179
Chapter 21. The Memento Pattern
...................................................................180
Motivation
.........................................................................................................180
Implementation
................................................................................................180
Sample Code
...................................................................................................181
Consequences of the Memento Pattern
......................................................187
Programs on the CD-ROM
............................................................................187
Chapter 22. The Observer Pattern
...................................................................189
Watching Colors Change
...............................................................................190
The Message to the Media
............................................................................193
The JList as an Observer
...............................................................................193
The MVC Architecture as an Observer
........................................................195
The Observer Interface and Observable Class
..........................................195
Consequences of the Observer Pattern
......................................................196
Programs on the CD-ROM
............................................................................196
Chapter 23. The State Pattern
..........................................................................197
Sample Code
...................................................................................................197
Switching between States
..............................................................................201
How the Mediator Interacts with the StateManager
...................................201
State Transitions
..............................................................................................204
Mediators and the God Class
........................................................................204
Consequences of the State Pattern
.............................................................205
Programs on the CD-ROM
............................................................................205
Chapter 24. The Strategy Pattern
.....................................................................206
Motivation
.........................................................................................................206
Sample Code
...................................................................................................206
The Context Class
...........................................................................................208
v
Plik z chomika:
blazejg
Inne pliki z tego folderu:
Wireless Java Developing with J2ME 2nd 2003.chm
(2615 KB)
Wireless J2ME Platform Programming , 2002.pdf
(2614 KB)
using uml for modeling a distributed java application 1997.pdf
(707 KB)
Using Java 2 Standard Ed 2001.chm
(6449 KB)
Using Enterprise JavaBeans 2.0 2002.chm
(1098 KB)
Inne foldery tego chomika:
130 linux and unix ebooks
132 C and C++ ebooks
156 database ebooks
237.For.Dummies.ebooks.Wiley.Publishing
Architecture e-books
Zgłoś jeśli
naruszono regulamin