s ravi chandran wrote:Please let me know how to control the sequence of events. Should I use a CountDownLatch or any other blocking construct to wait till registerItems() is called ?
Don't worry about the mechanics (blocking constructs, countdown latches, etc) right now; you'll tie yourself in knots. Concentrate on
what needs to happen.
What is an
Observer? How does it work? What
creates an
Observer?
Same questions for
Observable.
One possible idea: Forget about
Observer and
Observable for a minute, and just write a class that includes a
Scanner that continually reads a line from the keyboard.
If the line is "x", print out a message "got x"; if it's "y", print out "got y"; if it's "z", print out "got z"; and if it's "q", exit. And
make sure it works.
Now, instead of printing the messages directly, create three new classes:
XMessage,
YMessage and
ZMessage that print them for you - you could even
test them with your class before you go any further to make sure they work.
And
now try to tie them together as
Observers and
Observables.
Which one(s) need to be the
Observer and which one(s) the
Observable?
What do you have to do to "connect" your objects together so that they behave
exactly like your original class?
I think that'll help you to understand what the responsibility of each one is and how they link together, and NOW
you should be in a better position to implement your
Tracker and
Subject classes.
HIH
Winston