Sean, Fernando:
> instead, take out the hard reference to the class, and place it inside
> it's own message
>
> newActivator
> ^Activator new
>
> doSomethingInteresting
> | activator |
> activator := self newActivator.
> ...
>
>
> now a subclass can override #newActivator rather than havingto override
> doSomethingInteresting, and risk duplicating various pieces of code?
I think that the intent of the tip is that it should be expressed as:
activatorFactory
^ Activator
doSomethingInteresting
| activator |
activator := self activatorFactory new.
...
since otherwise there doesn't seem to be any reason for the advice to put the
factored-out method into the 'constants' category.
FWIW, I think the advice is wrong as stated. I think the code is much better
the way you have factored it. Of course, there's nothing to prevent you using
both factorings:
activatorFactory
^ Activator
makeActivator
^ self activatorFactory new.
doSomethingInteresting
| activator |
activator := self makeActivator.
...
but that looks like overkill to me, unless there is a need to refer to
Activator separately from its use in #makeActivator.
-- chris
...