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

B8.Prototype

Description

When we want to create an object starting from an existing object, this pattern proposes the definition of a method of cloning which masks in the client the effective operations of duplication.

Structure and Components

Structure and Components of the Prototype design pattern

Structure and Components of the Prototype design pattern

  • Prototype declares the interface of the operation of cloning with, if needed, an implemementation by defect,
  • Prototype1 and Prototype2 implement the operation of the appropriate cloning,
  • PrototypeClient creates new objects by requesting a prototype to clone itself cloner.

Collaborations

  • a customer asks an object to clone itself,
  • the operation of cloning is delegated to the subclasses.

Strengths and Weaknesses

Plus sign the encapsulation of the creation of an object and the client does not have explicit knowledge on the class of this object,

Plus sign allows the dynamic definition of classes of objects ratjer than a static definition made at compilation,

Plus sign allows the establishment of objects which are not differed by modifications made incrementally,

Minus sign the implementation of an operation of cloning can be difficult if there are components which cannot be cloned (operation of cloning not previously defined) or if there are circular references,

Minus sign the depth of the cloning of the components to be implemented can depend on the context of use.

Use in CBR*Tools

This pattern is used for the constitution by cloning of a library of measurements of similarity, for the copying of weight vectors and for the configuration of the traverse of the indices. To carry out these clones, all the accessible objects from a similarity establish to themselves an operation of cloning. This operation turns over a new object identical to the prototype or the same object, if this one is non-modifiable (it will thus be shared by all the clones).




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