CBR Logo


CBR*Tools Documentation


B1.Abstract Factory


B2.Adapter


B3.Chain of Responsibility


B4.Composite


B5.Facade


B6.Factory Method


B7.Iterator


B8.Prototype


B9.Strategy


B10.Template Method


Logo of Inria at Sophia Antipolis


French flag - link to the french documentation


Return to the Action AID
main page

Annex B: Design Patterns

B6.Factory Method

Description

When an algorithm needs to create an object whose its concrete class is variable according to the context, this owner proposes the delegation with a subclass of the instanciation of this object.

Structure and Components

Structure and Components of the Factory Method design pattern

Structure and Components of the Factory Method design pattern

  • Creator defines a method in which an object must be created and delegates this instantiation to one of its subclasses by the definition of a method to be specialised (method newProduct ),
  • Creator1 and Creator2 establish in a concrete way instanyiation of the required object,
  • Product defines the abstract interface of the object which is handled by Creator ,
  • Product1 and Product2 establish the behaviours of the objects to be used.

Collaborations

  • Creator delegates to its subclasses the instantiation of the necessary object.

Strengths and Weaknesses

Plus sign we do not have to specify the object to be instantiated directly and allows a subclass to choose the desired concrete object,

Minus sign in certain cases, the specialisation of the base-class is carried out only to specify the instantiation (heavier operation for example than to pass as a parameter the requested object). It is thus preferable to use this pattern when it is also necessary for other reasons to specialise the base-class.

Use in CBR*Tools

This pattern occurs in various algorithms of CBR*Tools and in particular in the internal protocols of the index for the creation of the objects holding the result of a search (of IndexResult class) so as to instantiate the adequate objects.




Valid XHTML 1.0! Valid CSS! Brigitte Trousse
Last modified: Fri Sep 28 13:51:57 MEST 2001