Click here to Skip to main content
15,921,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it by any means possible to:

I have an object that is IObservable and it has several IObserver object.
Can one (or more) of these IObserver objects create a new object (from an other class then itself) but make this new object also observer of the IObservable i have?
I wouldnt know how to write the code and get the new object subscribed to the original IObservable.

:~
Posted

To do that, the IObserver object creating the new IObserver object will need to have access to the instance of the IObservable object it's subscribed to. Whether that's so is an implementation detail.

I don't think there's anything wrong in doing that, although it does seem a little odd.
 
Share this answer
 
v2
Comments
Vincent Beek 19-Feb-11 9:32am    
Exactly, but how to get this access?
Nish Nishant 19-Feb-11 9:42am    
While it's probably not the best design, the IObserver implementation can store the IObservable in a member field.
Espen Harlinn 19-Feb-11 10:12am    
Good answer :)
Nish Nishant 19-Feb-11 10:13am    
Thanks Espen.
Hi
IObservable usually has a list/array to store the observers which should be an observer type. IObserver type has a function which will be called by the Observable. So Observers implemented it. So when you create new object if it is a IObserver type then you can add it to observable and the new Observer get notified.

It depends how you use the data in the new objects when notified.

Try and if got doubts you can post comments here
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900