Java™ Design Patterns: A Tutorial

Book description

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™ Design Patterns is exactly the tutorial resource you need. Accessible 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™ 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

  • 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.



    0201485397B04062001

    Table of contents

    1. Copyright
    2. Preface
    3. About the Author
    4. Acknowledgments
    5. 1. What Are Design Patterns?
      1. 1. Introduction
        1. Defining Design Patterns
        2. The Learning Process
        3. Studying Design Patterns
        4. Notes on Object-Oriented Approaches
        5. The Java Foundation Classes
        6. Java Design Patterns
      2. 2. UML Diagrams
        1. Inheritance
        2. Interfaces
        3. Composition
        4. Annotation
        5. JVISION UML Diagrams
        6. Visual SlickEdit Project Files
    6. 2. Creational Patterns
      1. 3. The Factory Pattern
        1. How a Factory Works
        2. Sample Code
        3. The Two Subclasses
        4. Building the Simple Factory
          1. Using the Factory
        5. Factory Patterns in Math Computation
          1. Thought Questions
        6. Programs on the CD-ROM
      2. 4. The Factory Method
        1. The Swimmer Class
        2. The Event Classes
        3. Straight Seeding
          1. Circle Seeding
        4. Our Seeding Program
        5. Other Factories
        6. When to Use a Factory Method
          1. Thought Question
        7. Programs on the CD-ROM
      3. 5. The Abstract Factory Pattern
        1. A GardenMaker Factory
        2. How the User Interface Works
        3. Adding More Classes
        4. Consequences of the Abstract Factory Pattern
          1. Thought Question
        5. Programs on the CD-ROM
      4. 6. The Singleton pattern
        1. Creating a Singleton Using a Static Method
        2. Exceptions and Instances
        3. Throwing an Exception
        4. Creating an Instance of the Class
        5. Providing a Global Point of Access to a Singleton Pattern
        6. The javax.comm Package as a Singleton
          1. Building a CommPortManager
        7. Other Consequences of the Singleton Pattern
          1. Thought Question
        8. Programs on the CD-ROM
      5. 7. The Builder Pattern
        1. An Investment Tracker
        2. Calling the Builders
        3. The List Box Builder
        4. The Check Box Builder
        5. Consequences of the Builder Pattern
          1. Thought Questions
        6. Programs on the CD-ROM
      6. 8. The Prototype Pattern
        1. Cloning in Java
        2. Using the Prototype
        3. Using the Prototype Pattern
        4. Prototype Managers
        5. Cloning Using Serialization
        6. Consequences of the Prototype Pattern
          1. Thought Question
        7. Programs on the CD-ROM
        8. Summary of Creational Patterns
    7. 3. Structural Patterns
      1. 9. The Adapter Pattern
        1. Moving Data between Lists
        2. Using the JFC JList Class
          1. The Object Adapter
          2. The Class Adapter
        3. Two-Way Adapters
        4. Pluggable Adapters
        5. Adapters in Java
          1. Thought Question
        6. Programs on the CD-ROM
      2. 10. The Bridge Pattern
        1. The Class Diagram
        2. Extending the Bridge
        3. Java Beans as Bridges
        4. Consequences of the Bridge Pattern
          1. Thought Question
        5. Programs on the CD-ROM
      3. 11. The Composite Pattern
        1. An Implementation of a Composite
        2. Computing Salaries
        3. The Employee Classes
        4. The Boss Class
        5. Building the Employee Tree
        6. Self-Promotion
        7. Doubly Linked List
        8. Consequences of the Composite Pattern
        9. A Simple Composite
        10. Composites in Java
        11. Other Implementation Issues
          1. Thought Questions
        12. Programs on the CD-ROM
      4. 12. The Decorator Pattern
        1. Decorating a CoolButton
        2. Using a Decorator
        3. The Class Diagram
        4. Decorating Borders in Java
        5. Nonvisual Decorators
        6. Decorators, Adapters, and Composites
        7. Consequences of the Decorator Pattern
          1. Thought Questions
        8. Programs on the CD-ROM
      5. 13. The Façade Pattern
        1. Building the Façade Classes
        2. Consequences of the Façade Pattern
        3. Notes on Installing and Running the dbFrame Program
          1. Thought Question
        4. Programs on the CD-ROM
      6. 14. The Flyweight Pattern
        1. Discussion
        2. Example Code
          1. The Class Diagram
          2. Selecting a Folder
        3. Flyweight Uses in Java
        4. Sharable Objects
        5. Copy-on-Write Objects
          1. Thought Questions
        6. Programs on the CD-ROM
      7. 15. The Proxy Pattern
        1. Sample Code
        2. Copy-on-Write
        3. Enterprise Java Beans
        4. Comparison with Related Patterns
          1. Thought Question
        5. Programs on the CD-ROM
        6. Summary of Structural Patterns
    8. 4. Behavioral Patterns
      1. 16. Chain of Responsibility Pattern
        1. Applicability
        2. Sample Code
        3. The List Boxes
        4. Programming a Help System
          1. Receiving the Help Command
        5. A Chain or a Tree?
        6. Kinds of Requests
        7. Examples in Java
        8. Consequences of the Chain of Responsibility
          1. Thought Questions
        9. Programs on the CD-ROM
      2. 17. The Command Pattern
        1. Motivation
        2. Command Objects
        3. Building Command Objects
        4. The Command Pattern
        5. The Command Pattern in the Java Language
        6. Consequences of the Command Pattern
          1. Anonymous Inner Classes
        7. Providing Undo
          1. Thought Questions
        8. Programs on the CD-ROM
      3. 18. The Interpreter Pattern
        1. Motivation
        2. Applicability
        3. Simple Report Example
        4. Interpreting the Language
        5. Objects Used in Parsing
        6. Reducing the Parsed Stack
        7. Implementing the Interpreter Pattern
          1. The Syntax Tree
        8. Consequences of the Interpreter Pattern
          1. Thought Question
        9. Programs on the CD-ROM
      4. 19. The Iterator Pattern
        1. Motivation
        2. Enumerations in Java
        3. Sample Code
        4. Filtered Iterators
          1. The Filtered Enumeration
        5. Consequences of the Iterator Pattern
        6. Composites and Iterators
        7. Iterators in Java 1.2
          1. Thought Question
        8. Programs on the CD-ROM
      5. 20. The Mediator Pattern
        1. An Example System
        2. Interactions between Controls
        3. Sample Code
          1. Initialization of the System
        4. Mediators and Command Objects
        5. Consequences of the Mediator Pattern
        6. Single Interface Mediators
        7. Implementation Issues
        8. Programs on the CD-ROM
      6. 21. The Memento Pattern
        1. Motivation
        2. Implementation
        3. Sample Code
        4. Consequences of the Memento Pattern
          1. Thought Question
        5. Programs on the CD-ROM
      7. 22. The Observer Pattern
        1. Watching Colors Change
        2. The Message to the Media
        3. The JList as an Observer
        4. The MVC Architecture as an Observer
        5. The Observer Interface and Observable Class
        6. Consequences of the Observer Pattern
          1. Thought Questions
        7. Programs on the CD-ROM
      8. 23. The State Pattern
        1. Sample Code
        2. Switching between States
        3. How the Mediator Interacts with the StateManager
        4. State Transitions
        5. Mediators and the God Class
        6. Consequences of the State Pattern
          1. Thought Questions
        7. Programs on the CD-ROM
      9. 24. The Strategy Pattern
        1. Motivation
        2. Sample Code
        3. The Context Class
        4. The Program Commands
        5. The Line and Bar Graph Strategies
        6. Drawing Plots in Java
        7. Consequences of the Strategy Pattern
          1. Thought Question
        8. Programs on the CD-ROM
      10. 25. The Template Pattern
        1. Motivation
        2. Kinds of Methods in a Template Class
        3. Template Method Patterns in Java
          1. AbstractTableModel
          2. AbstractBorder
          3. AbstractListModel
        4. Sample Code
          1. Drawing a Standard Triangle
          2. Drawing an Isoceles Triangle
          3. The Triangle Drawing Program
        5. Templates and Callbacks
        6. Consequences of the Template Pattern
          1. Thought Question
        7. Programs on the CD-ROM
      11. 26. The Visitor Pattern
        1. Motivation
        2. When to Use the Visitor Pattern
        3. Sample Code
        4. Visiting the Classes
        5. Visiting Several Classes
        6. Bosses Are Employees, Too
        7. Catch-All Operations Using Visitors
        8. Double Dispatching
        9. Traversing a Series of Classes
        10. Consequences of the Visitor Pattern
          1. Thought Question
        11. Programs on the CD-ROM
    9. 5. Design Patterns and the Java Foundation Classes
      1. 27. The JFC, or Swing
        1. Installing and Using Swing
        2. Ideas behind Swing
        3. The Swing Class Hierarchy
      2. 28. Writing a Simple JFC Program
        1. Setting the Look and Feel
        2. Setting the Window Close Box
        3. Making a JxFrame Class
        4. A Simple Two-Button Program
        5. More on JButton
        6. Programs on the CD-ROM
      3. 29. Radio Buttons and Toolbars
        1. Radio Buttons
        2. The JToolBar
        3. JToggleButton
        4. A Sample Button Program
        5. Programs on the CD-ROM
      4. 30. Menus and Actions
        1. Action Objects
        2. Design Patterns in the Action Object
        3. Programs on the CD-ROM
      5. 31. The JList Class
        1. List Selections and Events
        2. Changing a List Display Dynamically
        3. A Sorted JList with a ListModel
        4. Sorting More-Complicated Objects
        5. Getting Database Keys
        6. Adding Pictures in List Boxes
        7. Programs on the CD-ROM
      6. 32. The JTable Class
        1. A Simple JTable Program
        2. Cell Renderers
        3. Rendering Other Kinds of Classes
        4. Selecting Cells in a Table
        5. Patterns Used in This Image Table
        6. Programs on the CD-ROM
      7. 33. The JTree Class
        1. The TreeModel Interface
        2. Programs on the CD-ROM
        3. Summary
    10. 6. Case Studies
      1. 34. Sandy and the Mediator
      2. 35. Herb's Text Processing Tangle
      3. 36. Mary's Dilemma
      4. Bibliography

    Product information

    • Title: Java™ Design Patterns: A Tutorial
    • Author(s): James W. Cooper
    • Release date: February 2000
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780201485394