[Cuis] #when:send:to:
Juan Vuletich
juan at jvuletich.org
Mon Nov 16 18:11:51 CST 2015
Hi Dan,
On 13/11/2015 02:58 p.m., Dan Norton wrote:
> Hello Everyone,
>
> The following repo contains before and after examples of replacing the Dependency
> Mechanism with the Observer Pattern:
>
> https://github.com/dhnorton/Cuis-Smalltalk-light
>
> Please take a look at this and tell me what needs to change. I'm trying to supply an example
> of the Observer Pattern so that others might use #when:send:to: with less difficulty than I
> experienced. There may be better examples but I picked one from the Blue Book.
>
> It seems that #when:send:to: is necessary but not sufficient as a replacement for the
> Dependency Mechanism. In this example, it replaced #addDependent:, not #changed or
> #update and I am still not comfortable with how to choose the parameters. This may be an
> example of the difficulty in explaining the obvious, I'm not sure :-)
>
> The #changed method was replaced with #triggerEvent: with a symbol argument which is
> referred to in one of the arguments of #when:send:to: and that's the only constraint AFAICT.
>
> The #update: method was retained, as a convenience; it also needs to agree with one of the
> arguments of #when:send:to: and could have been different.
>
> Please tell me if any of this is wrong. Thanks.
>
> - Dan
I think the idea of #when:send:to: is to use event names and actions
that make sense to your model (and not #changed and #update:). For
instance, in Example2>>#lights:, I would change the line:
eachLight when: #changed send: #update: to: dependentLight
with: self
to read:
eachLight when: #turnedOn send: #turnOff to: dependentLight
And, in #turnOn, make it do:
self triggerEvent: #turnedOn
Doesn't this read better?
Cheers,
Juan Vuletich
More information about the Cuis
mailing list