[.] DejaVU Online: -- The OO Lectures
[.] - [up] [top] - [I] [II] [III] [IV] - [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] - [A] [R]

Creational Patterns


Factory

provide interface for creating family of related or dependent objects without specifying their concrete classes

Example

Also known as kit

Paricipants

Consequences

Implementation

See GOF
slide: Factory


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

Consequences

Related


slide: Factory Method


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
slide: Singleton


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

slide: Prototype


[.] - [up] [top] - [I] [II] [III] [IV] - [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] - [A] [R]
Hush Online Technology
hush@cs.vu.nl
02/15/00