I have been writing about the GOF design patterns for quite some time
now, and, this would be the last of the series. I will be writing about
the Memento pattern today which is a behavioral pattern. You can read
about the other patterns from the following links.
The memento pattern deals with capturing an object’s internal state and
saving it externally so that the internal state of that object can be
restored later. This pattern is usually used in computer games where the
state of the game can be saved, and can be started from the same point.
The following example illustrates the use of memento pattern.
The components that make up the memento pattern are the Originator,
for which the state has to be saved, the Caretaker which is a class
that holds the mementos and the Memento which holds the state of the
originator.
The memento pattern can be used when we need to save an object’s state
and retrieve it later or when we don’t want to expose an objects state
directly.
Comments