Performing a method on only those objects which will understand it

Andrew C. Greenberg werdna at mucow.com
Mon Jan 21 02:54:53 UTC 2002


On Sunday, January 20, 2002, at 09:26  PM, Jim Rosenberg wrote:

> Please pardon the Smalltalk 101ish nature of this question.
>
> I'm developing some morphs that have various behaviors that I need for 
> some interactive content.  In the process of doing this, I'm evolving 
> some selectors that "my" morphs understand, but a generic morph might 
> not understand.  I need a way to perform such a method on "my" morphs 
> without causing an error if the class does not implement the method.

...

> Is this the way this is "supposed to be" done?  Is there a Better Way 
> (TM)? This way seems reasonably straightforward, but I thought I'd ask 
> before I get to many of these things scattered all over my code.

You answer your question well with the very phrase "scattered all over 
my code."  This, in the OOD world, is what is referred to as a ''smell," 
a clue that the code needs to be refactored, or structured in a 
different way.

There are zillions of ways to do what you describe, the simplest,  far 
from the most elegant, but far more elegant than this code, would be to 
simply define a default method in Morph (or the GCD of the class 
hierarchy in which you will be working), that does something reasonable.

Even this has smells, although in some case it may be appropriate.  The 
real question that needs to be asked, however, is this: "why are you 
sending these methods to all those morphs?"  Perhaps the analysis should 
begin there.




More information about the Squeak-dev mailing list