2 Roles, Auxiliary Concepts, and Constraints
Consider again the Memento pattern. At a particular
point in the execution of our system, we may have a group
of objects interacting according to the Memento pattern.
That is, one object is playing the Originator role, another
the Caretaker role, a third object (or possibly more than
one if the caretaker object1 has taken multiple snapshots
of the originator object) the Memento role. At the same
time, another group of objects may also be interacting according
to the Memento pattern; indeed, as in the case of
object o1 in the scenario in Sec. 1, one or more objects
might belong to both groups. To allow for this, we will say
that there may be zero or more instances of a given pattern
at any time during the execution of the system. Individual
objects will enroll in a particular instance of a pattern to
play a particular role; the same object may be enrolled simultaneously
to play roles in different instances of the same
or different patterns; but it cannot simultaneously play multiple
roles in a given pattern instance.
How do we specify a pattern? Since we are dealing
with roles not classes, there are no specific data members
in terms of whose values we can express the requires and
ensures clauses of the individual methods. Hence we introduce,
in our pattern specifications, the needed data members
as part of the individual roles of the pattern, and use these