Performing a method on only those objects which will understand it

Noel J. Bergman noel at devtech.com
Mon Jan 21 22:24:53 UTC 2002


> 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.

Personally, I cringe when I read something like that.  As a general rule for
managing a public class library, I would consider it poor practice to add
personal behaviors to public classes.

The solution is pre-qualified as being far from elegant, but why not suggest
A Better Way, as the original question desired?  Is this really considered
good programming practice in Smalltalk?  If not, then why start a Smalltalk
101 programmer down such a poor practice in the first place?

> > If  everyone does this, there will be method explosion in class Morph
that
> >will get out of hand in no time flat.
> As opposed to the current situation, where there are only 1000 or so
methods
> in Morph?

And this is considered good?

> There is an essence of being a Morph, and it certainly would be nice if
people
> reading the code can focus on that essence to begin with.  Modules would
solve
> this problem nicely: the Morphic module would contain Morph's essential
methods,
> and Morph's other methods would be scattered among the modules they
support.

That sounds better, for when changing a public class is the necessary
approach.  At least it puts more control over the situation.  Will browsers
support modules, so that we can view classes not just by package but also by
module, and methods not just by category but also by module?  Yes, I did
search the Swiki for content mentioning Modules, but I didn't notice any
info on browsing once Modulars are part of the system.

	--- Noel




More information about the Squeak-dev mailing list