topical media & game development
pattern(s)
/ matrix
/ model(s)
/ resource(s)
design patterns

pattern(s)
/ matrix
/ model(s)
/ resource(s)
factory
provide interface for creating family of
related or dependent objects without
specifying their concrete classes
also known as kit
participants
- AbstractFactory, Concrete Factory, Abstract Product, Concrete Product
consequences
- isolate concrete classes
- makes exchanging product families easy
- promotes consistency among products
- supporting new kinds of products is difficult
implementation
See GOF

factory method
define interface for creating an object, but
let subclass decide which class to instantiate
also know as
virtual constructor
motivation
- encapsulates knowledge of which subclass to instantiate
applicability
- when a class can not anticpate the class of the objects it creates
- to delegate responsibility of object creation
structure
participants
- Product, ConcreteProduct, Creator, ConcreteCreator
consequences
- provide hooks for subclasses
- connects parallel class hierarchies
related

singleton
ensure a class has only one instance
and provide a global point of access
applicability
- only one instance of a class
- instance must be extendable by subclassing
implementation
// .h file
class Singleton {
public:
static Singleton instance();
protected: limit access
Singleton();
private:
static Singleton* _instance;
};
// .c file
Singleton* Singleton::_instance = 0;
Singleton* Singleton::instance() {
if (_instance == 0)
_instance = new Singleton();
return _instance;
}
consequences
- coordinate access to a single instance
- reduced namespace
- permit refinement
- permit variable number of instances
etcetera
see GOF

prototype
specify kinds of objects to create using a prototypical instance and create by copying
this prototype
motivation
- flexibility, reduce number of classes
applicability
participants
- Prototype, ConcretePrototype, Client
consequences
- adding and removing product types
at runtime
- specifying new objects by varying
value/structure
- reduced subclassing
- configure an application with classes dynamically
see kit.h and dv/tk/kit.c
related
- AbstractFactory versus Prototype

pattern(s)
/ matrix
/ model(s)
/ resource(s)
structural patterns
are concerned with how classes and objects
are composed to form larger structures

language mechanisms
- inheritance -- class
- delegation -- object
adaptor vs bridge
wrapper
- adaptor -- resolves inconsistencies between interfaces
- bridge -- relates abstraction to ... implementation
Composite vs Decorator vs Proxy
recursive composition
- Composite represents structure
- Decorator adds responsibilities
- Proxy regulates access

pattern(s)
/ matrix
/ model(s)
/ resource(s)
behavioral patterns
communication
deal with algorithms and the assignment of responsibilities between objects
class
- template method -- the skeleton of an algorithm
- interpreter -- to evaluate expressions
object
composition
- mediator -- provides indirection for loose coupling
- chain of responsibility -- connect objects to interact
- observer -- to handle dependencies

encapsulating behavior
objectify!
- strategy -- algorithm
- command -- request
- state -- object state -> behavioral change
- visitor -- to extract behavior from class
- iterator -- access and traversal

observer
one-to-many dependencies and notification
structure
consequences
- abstract coupling between subject and observer
- support for broadcast
- deals with unexpected updates
implementation
- mapping subjects to observers
- observing more than one subject?
- who triggers the update - subject or client of subject
- dangling references to subject
- consistency of subject (before notification)
- adding observer-specific update protocols (push / pull)
- specifying modifications of interest (aspects)
- how to encapsulate update semantics

(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.