Prev: Parsing XML Children
Next: in the Observer (Publish/Subscribe) pattern, are notificationsalien method calls?
From: neuneudr on 13 Sep 2009 05:30 First thanks to Lew and Mark who responded to my question about @ThreadSafe / FindBugs... Now I've got other questions: - In the Observer (aka Publish/Suscribe) design pattern, the notification about the observed subject state change is named a "callback" right? (terminology question) tmp.registerObserver( new Observer() { public void subjectHasChanged() { // do something now that we know the subject we were observing changed } } ); - In the Observer (aka Publish/Suscribe) design pattern, can't it be said that the notification about the observed subject change is an alien method call?
From: Scott A. Hightower on 13 Sep 2009 07:47
<neuneudr(a)yahoo.fr> wrote in message news:a7937399-19a5-462d-927c-40cd498aeff4(a)s15g2000yqd.googlegroups.com... > First thanks to Lew and Mark who responded to my question about > @ThreadSafe / FindBugs... > > Now I've got other questions: > > - In the Observer (aka Publish/Suscribe) design pattern, the > notification about the observed subject state change is named a > "callback" right? (terminology question) > > tmp.registerObserver( new Observer() { > public void subjectHasChanged() { > // do something now that we know the subject > we were observing changed > } > } ); > > - In the Observer (aka Publish/Suscribe) design pattern, can't it be > said that the notification about the observed subject change is an > alien method call? > Yes. Your class invokes a method whose definition is not under your control. As long as encapsulation is not broken, state integrity is maintained. You have control over what you pass to the method, as well as the rest of your class definition, so encapsulation is broken only if you allow it. You also have control over when you invoke the method. Therefore, deadlock can occur only if you allow it. Finally, there is a contract, which may or may not be under your control. (There may be more than one; the Observer implementation, for instance.) If explicit, the contract(s) may spell out prohibited actions, such as invoking mutator methods in a callback. If so, you may choose to relax your vigilance, after considering the cost of protection against prohibited actions. |