Tuesday, August 7, 2007

Fundamental Design Patterns by Functionalities


Simplifying idioms
Messenger
Collecting Parameter

Object quantity
Singleton
Object pool

Object decoupling
Proxy: fronting for another object
The PoolManager using Proxy
Dynamic Proxies
State: changing object behavior
Iterators: decoupling algorithms from containers

Factoring commonality
Strategy: choosing the algorithm at run-time
Policy: generalized strategy
Template method

Encapsulating creation
Simple Factory method
Polymorphic factories
Abstract factories

Specialized creation
Prototype
Builder

Too many
Flyweight: too many objects
Decorator: too many classes

Connecting different types
Adapter
Bridge

Flexible structure
Composite

System decoupling
Observer
Mediator

Reducing interface complexity
Facade
Package as a variation of Facade

Algorithmic partitioning
Command: choosing the operation at run-time
Chain of responsibility

Externalizing object state
Memento

Complex interactions
Multiple dispatching
Visitor, a type of multiple dispatching

Complex system states
State Machine
Table-Driven State Machine
The state class
Conditions for transition
Transition actions
The table
The basic machine
Simple vending machine
Testing the machine
Tools
Table-driven code: configuration functionality
Table-driven code using anonymous inner classes

Pattern refactoring
Simulating the trace recycler
Improving the design
"Make more objects"
A pattern for prototype creation
Trash subclasses
Parsing Trash from an external file
Recycling with prototyping
Abstracting usage
Multiple dispatching
Implementing the double dispatch
The Visitor pattern
A Reflective Decorator
More coupling?
RTTI considered harmful?