reverse observer pattern
hi,
is it possible to use the reverse of observer pattern
i.e - observer pattern is described normally as there is 1 subject & many observers.
So when the subject changes, it notifies the observers. My problem is I only 1 observer but many things change, so when each of the things (subjects ) change I want to call the observer to get the updates.
Is it possible?
What if the each subject is run in a thread.?
Thank you
[467 byte] By [
AlienXa] at [2007-11-27 9:16:02]

# 2
first of all I just wanted to get an idea on that observer pattern thing in each case.
secondly yes Ive gone far with that making subjects run in different threads. kinda stuck in there on how to get the next part done. which is to get the completed work from the threads to one observer & do what is required.
In this scenario I need to make the subjects run in threads as its about processing input stream from network... :(
thanks.
# 3
No, it's not possible. Compilers are specifically written to catch this pattern and throw it out</lie>Seriously, what worth has this question? Wouldn't it be quicker, simpler, more useful and more satisfying to write some code to try it?
# 4
> is it possible to use the reverse of observer pattern
> i.e - observer pattern is described normally as there
> is 1 subject & many observers.
> So when the subject changes, it notifies the
> observers. My problem is I only 1 observer but many
> things change, so when each of the things (subjects )
> change I want to call the observer to get the
> updates.
> Is it possible?
Yes. Rather than have classes A, B, C register as listeners on class D, have class D register itself as a listener on classes A, B, C. Whenever A, B, or C do something, they'll notify all classes observing them (namely D).
This is not the inverse of observer pattern but rather a different way of utilizing it than what you have described in your question.
>
> What if the each subject is run in a thread.?
>
If classes A, B, C run in separate threads, the pattern implementation does not change too terribly much. Whenever A, B, C do something they will still notify their observers (namely D). But you should realize that since they are multithreaded you may encounter a time when A and B notify D simultaneously. You will need to think about synchronization.