does squeak have an equivalent of #askFor:

Diego Fernandez diegof79 at gmail.com
Sun Aug 13 04:22:31 UTC 2006


On 8/12/06, Keith Hodges <keith_hodges at yahoo.co.uk> wrote:
> Diego Fernandez wrote:
> > Ouch!
> > IMHO a lot of #isThis or #isThat shows the lack of some abstractions.
> > Maybe you can solve it a better way.
> >
> why?

Because if you have an object that responds to isBanana method, you
end with code like this:
anObject isBanana ifTrue: [ "do something with anObject" ]
                             ifFalse: [ "do another thing with anObject" ].

"do something..."/"do another thing" is behavior specific to anObject,
so why is not a message to anObject? Why you can't have a message
polymorphic to "bananas" and "non-bananas"?
There are cases when is more simply to have the #isMethod.
But each time that I found cases like this, I think: What is the
abstraction that I'm missing?
My rule of thumb is: Avoid ifTrue/ifFalse...:P
Each "if" is a decision, a behavior specific to an object, so in most
cases it can be resolved using messages sends. (I'm not saying that is
easy to do that, and in complex cases maybe the "if" is better, but
thinking about the design and what is missing that you need the "if"
is a good practice).

Regards,
Diego



More information about the Squeak-dev mailing list