1. UTAH STATE UNIVERSITY
COMPUTER SCIENCE
CS-7350 Reading Assignment
GoF Patterns: Mediator, Memento, Observer
Jorge Edison Lascano
Spring 2012
02-01-2012
MEDIATOR, MEMENTO, OBSERVERGoFPATTERNS
Mediator, a centralizer that encapsulates communication and orchestration among several
objects by handling a cooperative behavior; interaction may be in pairs or in group.Could we
have some mediators?-Yes, we may need a mediator tree, where the root will be the main
mediator. Should we use Push or Pull techniques for managing global behavior?-It will depend
on the application, e.g. if it is a real time application, both techniques should be applied to notify
and update every object and to keep updated global state. Every object must update the
cooperative behavior.
Memento,captures and externalize an object state to let go back to previous state.The Memento
itself only contains one object state, so it needs a Caretaker to control several states. How to
ensure encapsulation?It can be done by the use of friends or in a blind way, Prototype pattern
may help, it may be expensive if little info represents the state, it would only make sense if the
whole object structure is needed to save its state, i.e. caching technique.How to implement a
complete undo feature?By using Command + Memento(s) + Iterator + Mediator(s).
Observer, Based on broadcast communication, dependent objects are told about state changes of
the others.How to tell the others about changes? By using a push/pull model, but this may
introduce a problem of uncontrolled updates (vulnerable to a kind of denial-of-service attack),
then a controller (mediator) that handles semantic rules and communication protocol must be
used. This pattern is already implemented in almost every Web 2.0 application, mainly on those
which applies AJAX, e.g. gmail.