views:

157

answers:

1

The Observer Pattern seems very much like a Notifier Pattern, since it is based on the subject notifying objects that are interested. The "notify" part seems the most important, because without it, nothing gets notified.

(was there ever some thoughts to rename this pattern to the Notifier Pattern?)

Are there any Observer Patterns out there that are more "observer based"?

For example, one that has a timer so that the observers will look into the object being observed every n milliseconds.

Or one that (like in machine code), when a routine wants to observe a memory location, it calls a certain routine and says, "if memory location TEMPERATURE_VALUE (0x32FF2C12, for example) gets modified, then call me (it knows the value is modified by the interrupt mechanism). In this case, the subject doesn't notify or cannot decide whether to notify or not, but is forced to be observed.

+1  A: 

The observer pattern is so named because the objects attached to the subject object "observe" its behavior. That the mechanism for such observance (a push of information from the subject to the observer) is initiated by the subject object does not change the inherent function of the observer objects (namely, that of observing).

The pattern might be better described as a "subscriber pattern," in that the observer objects "subscribe" to events on the subject object, and thereafter "listen" to those events. It would be accurate to say that the observer object does not observe the subject object directly, but rather indirectly through the information provided to it through the subject object's firing of the subscribed events.

It wouldn't be the first time a pattern was misnamed. Inversion of Control sounds really complicated until you realize that all that really means is providing needed objects (dependencies) to a class by assigning them to parameters in a constructor. The term "Dependency Injection" was coined in an effort to make this concept clearer.

Robert Harvey
All true. Observer is frequently called Publish/Subscribe (Pub/Sub) (though not strictly accurate), and in Java Subscribers are ActionListeners and EventListeners. So all of those names are "observed" in the wild... :) (Couldn't resist)
Drew Hall
While IoC isn't the most intuitive of names, it describes what the pattern does fairly well :)
Mark Simpson