This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes ObserverPattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ObserverPattern " Watch "ObserverPattern " New topic
Author

ObserverPattern

Ramesh Kumar Swarnkar
Ranch Hand

Joined: Sep 15, 2003
Posts: 84
Hi,
I need to look some very simple code example for ObserverPattern.
can any one give some example for beginner level code.

regards,
Ramesh
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Have a look at this
By the way, jdk also provides an implementation for this pattern, here are the related classes:

Observable

Observer


apigee, a better way to API!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Ah yes, java.util.Observable...

It can be used as an example on how to implement this yourself, but I find the class highly unusable - if you want to use it, your classes must become subclasses of Observable. It should have been an interface instead, with a default implementation like AbstractObservable or DefaultObservable.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ObserverPattern