Observer pattern

Soldato
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
A quick question about this pattern can something be both the subject and an observer itself? If so is this advisable?

Imagine the scenario:

You have a user interface with a load of text fields, these text fields are populated by the UI's associated file input stream. This input stream has a list of sections (observers of the file).

If an update happens to the UI both the file and it's associated sections will need to be updated.

So by my reckoning the input stream will be being observed by it's subscribed sections and it will also be observing the UI itself.
 
ByteJuggler said:
You could conceivably even have the sections observe some observable version of the filestream, so that if it's updated, the section(s) will be notified, which in turn will notify the UI to update itself. In this scenario, your sections will then therefore be both observers and subjects, observing the filestream, and being observed by the UI.

Thanks BJ that clarifies a few things for me. I may have more questions after my brain has absorbed all this information properly :p
 
Back
Top Bottom