Prototype

Intent

Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

Class diagram of the original GoF pattern

structure-GoF:prototype

Improvement in MixJuice

Solved Problem(s)

Introduction problem
Original GoF pattern can not be introduced to the existing program without modifying the source code. (This problem is mentioned at p.120, line.37-39 in the GoF book.)

Used programming technique(s)

Abstract method addition of "copy()" method to the existing classes.

Consequences

Structure and pseudo code

structure:prototype_sample1

module original {
  define abstract class AbstractProduct {...}
  define class ConcreteProduct1 extends AbstractProduct {...}
  define class ConcreteProduct2 extends AbstractProduct {...}
}

module extension extends original {
  class AbstractProduct {
    define abstract AbstractProduct copy();
  }

  class ConcreteProduct1 {
    AbstractProduct copy() {...}
  }

  class ConcreteProduct2 {
    AbstractProduct copy() {...}
  }
}

Akira TANAKA <akr@m17n.org>, Yuuji ICHISUGI <y-ichisugi@aist.go.jp>

Top