topical media & game development
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

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