Home > Store

Java? Design Patterns: A Tutorial

Register your product to gain access to bonus material or receive a coupon.

Java? Design Patterns: A Tutorial

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2000
  • Dimensions: 7-1/4" x 9-1/4"
  • Pages: 352
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-48539-7
  • ISBN-13: 978-0-201-48539-4

Java developers know that design patterns offer powerful productivity benefits -- but until now, few patterns books have been specific enough to address their programming challenges. With Java Design Patterns, there's finally a hands-on, practical design patterns guide focused specifically on real-world Java development. Java Design Patterns is structured as a series of short chapters, each describing one Java 1.2 design pattern and providing one or more complete, working, visual example programs, complete with UML diagrams illustrating how the classes interact. The book covers three main categories of design patterns: creational, structural, and behavioral. Author James W. Cooper demonstrates several patterns at work in the context of development with the Java Foundation Classes (JFC) and Swing; and also presents several detailed case studies of Java development with design patterns. For all Java programmers, software engineers, and application developers.

Sample Content

Table of Contents



Preface.


Acknowledgments.

I. WHAT ARE DESIGN PATTERNS?

1. Introduction.

Defining Design Patterns.

The Learning Process.

Studying Design Patterns.

Notes on Object-Oriented Approaches.

The Java Foundation Classes.

Java Design Patterns.

2. UML Diagrams.

Inheritance.

Interfaces.

Composition.

Annotation.

JVISION UML Diagrams.

Visual SlickEdit Project Files.

II. CREATIONAL PATTERNS.

3. The Factory Pattern.

How a Factory Works.

Sample Code.

The Two Subclasses.

Building the SimpleFactory.

Factory Patterns in Math Computation.

Thought Questions.

4. The Factory Method.

The Swimmer Class.

The Event Classes.

Straight Seeding.

Our Seeding Program.

Other Factories.

When to Use a Factory Method.

Thought Question.

5. The Abstract Factory Pattern.

A GardenMaker Factory.

How the User Interface Works.

Adding More Classes.

Consequences of the Abstract Factory Pattern.

Thought Question.

6. The Singleton Pattern.

Creating a Singleton Using a Static Method.

Exceptions and Instances.

Throwing an Exception.

Creating an Instance of the Class.

Providing a Global Point of Access to a Singleton Pattern.

The javax.comm Package as a Singleton.

Other Consequences of the Singleton Pattern.

Thought Question.

7. The Builder Pattern.

An Investment Tracker.

Calling the Builders.

The List Box Builder.

The Check Box Builder.

Consequences of the Builder Pattern.

Thought Questions.

8. The Prototype Pattern.

Cloning in Java.

Using the Prototype.

Using the Prototype Pattern.

Prototype Managers.

Cloning Using Serialization.

Consequences of the Prototype Pattern.

Thought Question.

Summary of Creational Patterns.

III. STRUCTURAL PATTERNS.

9. The Adapter Pattern.

Moving Data between Lists.

Using the JFC JList Class.

Two-Way Adapters.

Pluggable Adapters.

Adapters in Java.

Thought Question.

10. The Bridge Pattern.

The Class Diagram.

Extending the Bridge.

Java Beans as Bridges.

Consequences of the Bridge Pattern.

Thought Question.

11. The Composite Pattern.

An Implementation of a Composite.

Computing Salaries.

The Employee Classes.

The Boss Class.

Building the Employee Tree.

Self-Promotion.

Doubly Linked List.

Consequences of the Composite Pattern.

A Simple Composite.

Composites in Java.

Other Implementation Issues.

Thought Questions.

12. The Decorator Pattern.

Decorating a CoolButton.

Using a Decorator.

The Class Diagram.

Decorating Borders in Java.

Nonvisual Decorators.

Decorators, Adapters, and Composites.

Consequences of the Decorator Pattern.

Thought Questions.

13. The Faade Pattern.

Building the Faade Classes.

Consequences of the Faade Pattern.

Notes on Installing and Running the dbFrame Program.

Thought Question.

14. The Flyweight Pattern.

Discussion.

Example Code.

Flyweight Uses in Java.

Sharable Objects.

Copy-on-Write Objects.

Thought Question.

15. The Proxy Pattern.

Sample Code.

Copy-on-Write.

Enterprise Java Beans.

Comparison with Related Patterns.

Thought Question.

Summary of Structural Patterns.

IV. BEHAVIORAL PATTERNS.

16. Chain of Responsibility Pattern.

Applicability.

Sample Code.

The List Boxes.

Programming a Help System.

A Chain or a Tree?

Kinds of Requests.

Examples in Java.

Consequences of the Chain of Responsibility.

Thought Questions.

17. The Command Pattern.

Motivation.

Command Objects.

Building Command Objects.

The Command Pattern.

The Command Pattern in the Java Language.

Consequences of the Command Pattern.

Providing Undo.

Thought Questions.

18. The Interpreter Pattern.

Motivation.

Applicability.

Simple Report Example.

Interpreting the Language.

Objects Used in Parsing.

Reducing the Parsed Stack.

Implementing the Interpreter Pattern.

Consequences of the Interpreter Pattern.

Thought Question.

19. The Iterator Pattern.

Motivation.

Enumerations in Java.

Sample Code.

Filtered Iterators.

Consequence of the Iterator Pattern.

Composites and Iterators.

Iterators in Java 1.2.

Thought Question.

20. The Mediator Pattern.

An Example System.

Interactions between Controls.

Sample Code.

Mediators and Command Objects.

Consequences of the Mediator Pattern.

Single Interface Mediators.

Implementation Issues.

21. The Memento Pattern.

Motivation.

Implementation.

Sample Code.

Consequences of the Memento Pattern.

Thought Question.

22. The Observer Pattern.

Watching Colors Change.

The Message to the Media.

The JList as an Observer.

The MVC Architecture as an Observer.

The Observer Interface and Observable Class.

Consequences of the Observer Pattern.

Thought Questions.

23. The State Pattern.

Sample Code.

Switching between States.

How the Mediator Interacts with the StateManager.

State Transitions.

Mediators and the God Class.

Consequences of the State Pattern.

Thought Questions.

24. The Strategy Pattern.

Motivation.

Sample Code.

The Context Class.

The Program Commands.

The Line and Bar Graph Strategies.

Drawing Plots in Java.

Consequences of the Strategy Pattern.

Thought Question.

25. The Template Pattern.

Motivation.

Kinds of Methods in a Template Class.

Template Method Patterns in Java.

Sample Code.

Templates and Callbacks.

Consequences of the Template Pattern.

Thought Question.

26. The Visitor Pattern.

Motivation.

When to Use the Visitor Pattern.

Sample Code.

Visiting the Classes.

Visiting Several Classes.

Bosses are Employees, Too.

Catch-All Operations Using Visitors.

Double Dispatching.

Traversing a Series of Classes.

Consequence of the Visitor Pattern.

Thought Question.

V. DESIGN PATTERNS AND THE JAVA FOUNDATION CLASSES.

27. The JFC, or Swing.

Installing and Using Swing.

Ideas behind Swing.

The Swing Class Hierarchy.

28. Writing a Simple JFC Program.

Setting the Look and Feel.

Setting the Window Close Box.

Making a JxFrame Class.

A Simple Two-Button Program.

More on JButton.

29. Radio Buttons and Toolbars.

Radio Buttons.

The JToolBar.

JToggleButton.

A Sample Button Program.

30. Menus and Actions.

Action Objects.

Design Patterns in the Action Object.

31. The JList Class.

List Selections and Events.

Changing a List Display Dynamically.

A Sorted JList with a ListModel.

Sorting More-Complicated Objects.

Getting Database Keys.

Adding Pictures in List Boxes.

Programs on the CD-ROM.

32. The JTable Class.

A Simple JTable Program.

Cell Renderers.

Rendering Other Kinds of Classes.

Selecting Cells in a Table.

Patterns Used in This Image Table.

33. The JTree Class.

The TreeModel Interface.

Summary.

IV. CASE STUDIES.

34. Sandy and the Mediator.
35. Herb's Text Processing Tangle.
36. Mary's Dilemma.
Bibliography.

Preface

This is a practical book that tells you how to write Java programs using some of the most common design patterns. It is structured as a series of short chapters, each describing a design pattern and giving one or more complete, working, visual example programs that use that pattern. Each chapter also includes Unified Modeling Language (UML) diagrams illustrating how the classes interact.

This book is not a "companion" book to the well-known Design Patterns text Gamma, 1995 by the "Gang of Four." Rather, it is a tutorial for people who want to learn what design patterns are about and how to use them in their work. You need not have read Design Patterns to gain from reading this book, but when you are done here you might want to read or reread that book to gain additional insights.

In this book, you will learn that design patterns are a common way to organize objects in your programs to make those programs easier to write and modify. You'll also see that by familiarizing yourself with these design patterns, you will gain a valuable vocabulary for discussing how your programs are constructed.

People come to appreciate design patterns in different ways--from the highly theoretical to the intensely practical--and when they finally see the great power of these patterns, they experience an "Aha!" moment. Usually this moment means that you suddenly had an internal picture of how that pattern can help you in your work.

In this book, we try to help you form that conceptual idea, or gestalt, by describing the pattern in as many ways as possible. The book is organized into six main sections:

  • An introductory description
  • A description of patterns grouped into three sections: Creational, Structural, and Behavioral
  • A description of the Java Foundation Classes (JFC) showing the patterns they illustrate
  • A set of case studies where patterns have been helpful

For each pattern, we start with a brief verbal description and then build simple example programs. Each example is a visual program that you can run and examine so as to make the pattern as concrete as possible. All of the example programs and their variations are on the CD-ROM that accompanies this book. In that way, you can run them, change them, and see how the variations that you create work.

All of the programs are based on Java 1.2, and most use the JFC. If you haven't taken the time to learn how to use these classes, there is a tutorial covering the basics in Appendix A where we also discuss some of the patterns that they illustrate.

Since each of the examples consists of a number of Java files for each of the classes we use in that example, we also provide a Visual SlickEdit project file for each example and place each example in a separate subdirectory to prevent any confusion.

As you leaf through the book, you'll see screen shots of the programs we developed to illustrate the design patterns; these provide yet another way to reinforce your learning of these patterns. You'll also see UML diagrams of these programs that illustrate the interactions between classes in yet another way. UML diagrams are just simple box and arrow illustrations of classes and their inheritance structure, with the arrows pointing to parent classes and dotted arrows pointing to interfaces. If you are unfamiliar with UML, we provide a simple introduction in the first chapter.

Finally, since we used JVISION to create the UML diagrams in each chapter, we provide the original JVISION diagram files for each pattern as well, so you can use your own copy of JVISION to play with them.

When you finish this book, you'll be comfortable with the basics of design patterns and will be able to start using them in your day to day Java programming work.

James W. Cooper
Wilton, CT
Nantucket, MA
November, 1999


0201485397P04062001

Updates

Errata

Click below for Errata related to this title:

The following Errata details changes made to the text for the second printing of Java™ Design Patterns. Each pdf file contains corrected text from the second printing. The text had been highlighted in yellow to indicate where the changes have been made.

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020