Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ObserverPattern

 
Ramesh Kumar Swarnkar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this
By the way, jdk also provides an implementation for this pattern, here are the related classes:

Observable

Observer
 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic