Memento

Intent

Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later.

Class diagram of the original GoF pattern

structure-GoF:memento

Improvement in MixJuice:

Solved Problem(s)

Information hiding problem
Internal state of Memento should be accessible from Originator but hidden from clients. (This problem is mentioned at p.286,line.25-26 in the GoF book.) Note that this problem is also solved by the package/nested-class mechanisms of Java.

Used programming technique(s)

Namespace separation of Memento.

Consequences

Structure and pseudo code

structure:memento_sample1

module m {
  define class Originator {
    define abstract void setMemento(Memento m);
    define abstract Memento createMemento();
  }

  define class Memento {}
}

module m.implementation extends m {
  class Originator {
    int state;
    void setMemento(Memento m) {...}
    Memento createMemento() {...}
  }

  class Memento {
    int state;
  }
}

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

Top