You are previewing Holub on Patterns: Learning Design Patterns by Looking at Code.
O'Reilly logo
Holub on Patterns: Learning Design Patterns by Looking at Code

Book Description

The existing books on design patterns take a catalog approach, where they show the individual design patterns in isolation. This approach is fundamentally flawed, because you can't see how the design patterns actually function in the real world. Most programmers learn by looking at computer programs.

Holub on Patterns: Learning Design Patterns by Looking at Code teaches you design patterns in exactly this way: by looking at computer programs and analyzing them in terms of the patterns that they use. Consequently, you learn how the patterns actually occur in the real world and how to apply the patterns to solve real problems.

This book also looks at the broader context of object-oriented (OO) design and how patterns solve commonplace OO design problems. It covers many of the principles of OO design—principles not covered by most books on Java—and shows you how to apply these principles to make your code easier to maintain and debug.

Table of Contents

  1. Coverpage
  2. Titlepage
  3. Copyright
  4. Dedication
  5. Contents
  6. About the Author
  7. Acknowledgments
  8. Preface
  9. CHAPTER 1 Preliminaries: OO and Design Patterns
    1. Patterns vs. Idioms
    2. So What Is a Design Pattern, Anyway?
    3. So, What’s It All Good For?
    4. The Role of Patterns in Design
      1. The Tension Between Patterns and Simplicity
    5. Classifying Patterns
      1. On Design, Generally
      2. Programming FORTRAN in Java
      3. Programming with Your Eyes Open
    6. What Is an Object?
      1. Balderdash!
      2. An Object Is a Bundle of Capabilities
      3. How Do You Do It Wrong?
      4. So How Do You Do It “Right?”
    7. Cellular Automata
    8. Getters and Setters Are Evil
      1. Render Thyself
      2. JavaBeans and Struts
      3. Refactoring
      4. Life Without Get/Set
      5. When Are Accessors and Mutators Okay?
      6. Summing Up the Getter/Setter Issues
  10. CHAPTER 2 Programming with Interfaces, and a Few Creational Patterns
    1. Why extends Is Evil
    2. Interfaces vs. Classes
      1. Losing Flexibility
      2. Coupling
      3. The Fragile-Base-Class Problem
      4. Multiple Inheritance
      5. Frameworks and the Template-Method and Factory-Method Patterns
      6. Summing Up Fragile Base Classes
    3. When extends Is Appropriate
    4. Getting Rid of extends
      1. Factories and Singletons
      2. Singleton
      3. Threading Issues in Singleton
      4. Double-Checked Locking (Don’t Do It)
      5. Killing a Singleton
      6. Abstract Factory
      7. Pattern Stew
      8. Dynamic Creation in a Factory
      9. Command and Strategy
    5. Summing Up
  11. CHAPTER 3 The Game of Life
    1. Get a Life
    2. Charting the Structure of Life
    3. The Clock Subsystem: Observer
      1. Implementing Observer: The Publisher Class
    4. The Clock Subsystem: The Visitor Pattern
    5. The Menuing Subsystem: Composite
    6. The Menuing Subsystem: Facade and Bridge
    7. The MenuSite
    8. The Core Classes
      1. The Universe Class
      2. The Cell Interface
      3. The Resident Class
      4. The Neighborhood Class
    9. Mediator
    10. Composite Revisited
      1. Prototype
    11. Composite Redux
    12. Flyweight
      1. Flyweight Pools
    13. Memento
    14. Loose Ends
    15. Summing Up
  12. CHAPTER 4 Implementing Embedded SQL
    1. The Requirements
    2. The Architecture
    3. The Data-Storage Layer
      1. The Table Interface
      2. The Bridge Pattern
      3. Creating a Table, Abstract Factory
      4. Creating and Saving a Table: Passive Iterators and Builder
      5. Populating the Table
      6. Examining a Table: The Iterator Pattern
      7. Implementing Transactions (Undo) with the Command Pattern
      8. Modifying a Table: The Strategy Pattern
      9. Selection and Joins
      10. Miscellany
      11. Variants on the Table: The Decorator Pattern
    4. Adding SQL to the Mix
      1. SQL-Engine Structure
      2. Input Tokenization, Flyweight Revisited, and Chain of Responsibility
      3. The Scanner: Chain of Responsibility
      4. The ParseFailure Class
    5. The Database Class
      1. Using the Database
      2. The Proxy Pattern
      3. The Token Set and Other Constants
    6. The Interpreter Pattern
      1. Supported SQL
      2. Watching the Interpreter in Action
    7. The JDBC Layer
    8. The State Pattern and JDBCConnection
      1. Statements
      2. The Adapter Pattern (Result Sets)
      3. Finishing Up the Code
      4. When Bridges Fail
    9. Whew!
  13. APPENDIX A Design-Pattern Quick Reference
    1. Creational Patterns
      1. Abstract Factory
      2. Builder
      3. Factory Method
      4. Prototype
      5. Singleton
    2. Structural Patterns
      1. Adapter
      2. Bridge
      3. Composite
      4. Decorator
      5. Facade
      6. Flyweight
      7. Proxy
    3. Behavioral Patterns
      1. Chain of Responsibility
      2. Command
      3. Interpreter
      4. Iterator
      5. Mediator
      6. Memento
      7. Observer (Publish/Subscribe)
      8. State
      9. Strategy
      10. Template Method
      11. Visitor
  14. INDEX