
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Observing Additions and Modifications to a Hashtable
|
525
this.key = key;
this.value = value;
}
private object key = null;
private object value = null;
private bool keepChanges = true;
public bool KeepChanges
{
get {return (keepChanges);}
set {keepChanges = value;}
}
public object Key
{
get {return (key);}
}
public object Value
{
get {return (value);}
}
}
Discussion
The observer design pattern allows one or more observer objects to act as spectators
over one or more subjects. Not only do the observer objects act as spectators, but
they can also induce change in the subjects. According to this pattern, any subject is
allowed to register itself with one or more observer objects. Once this is done, the
subject can operate as it normally does. The key feature is that the subject doesn’t
have to know what it is being observed by—this allows the coupling between sub-
jects and observers to be minimized. The observer object(s) will then be notified of
any changes in state to the subjects. When the subject’s state changes, the observer
object(s) can change the state of other objects in the system to bring them into line
with changes that were made to the subject(s). In addition, the observer could even
make changes or refuse changes to the subject(s) themselves.
The observer pattern is best ...