Friday, February 5, 2010

Observer Pattern

Observer Pattern
Participants : Observer,Subject
An observer listens to the changes that happen to an observable subject.

Observer pattern is useful when a notification is to be sent to a group of objects when any state change happens to a subject.
Objects which listen to the state changes of a subject is called Observer.

Java provides the following classes to implement a Observer design pattern
java.util.Observable - The subject should extend this class
java.util.Observer - The observer/listener class should extend this class

useful methods are
java.util.Observable
addObserver - to add a new observer
deleteObserver - to delete an observer
setChanged - to mark the subject as changed
notifyObservers - to notify the observers about state change
java.util.Observer
update - called whenever the observed method is changed

Labels: ,


Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]