observer pattern question #1 (reference to subject)

Ville M. Vainio vivainio at gmail.com
Thu May 8 11:02:01 EDT 2008


Alan Isaac <aisaac at american.edu> writes:


> Is anything lost by not maintaining this reference (other
>
> than error checking ...)?  If I feel the observer needs
>
> access to the subject, what is wrong with just having the
>
> subject pass itself as part of the notification?

It reduces the number of places the observer can be called from,
because now the event source is part of the function signature. If you
omit the event source in the signature, you gain looser coupling -
it's the observer business to create the dependency.

Also, consider the situation where you want all investors to refresh
their idea about stock prices (because of, short network
failure). It's easy to run through a list of them and call update()
for everybody, while it's not so easy to find out what stock the
investor is observing (that's the investors business!) and pass that
object to the investor in the call.

Are these school questions btw? ;-)



More information about the Python-list mailing list