Peeping At The KeyHole
Ralph Johnson
johnson at cs.uiuc.edu
Mon May 1 17:59:20 UTC 2006
On 5/1/06, SmallSqueak <smallsqueak at rogers.com> wrote:
>
> About adding methods to existing classes ....
>
> Is this a rule, that I have to add methods to existing classes?
> Would you please explain why it is a good thing.
You don't have to, but you can. You can't do it in C++ or Java. It is a
good thing because sometimes when you want to extend a system, you want old
objects to interact well with new objects, and it is easier if you can add
methods to old objects. And I really mean "old objects" and not just "old
classes", though of course that is included.
Suppose you want to add a new kind of tool to the system, one that helps you
debug objects. You want to be able to send a message "debug" to every
object. You can add a default "debug" method to class Object and override
that method in classes that need a different implementation.
What if the authors of the existing classes don't want
> anything added to their classes?
When you publish the source code to something, it is a gift to the world.
The world can do what it wants with it. If you think the world is better
off without adding methods to a particular class, by all means write a
comment to that effect. But you might be wrong, and the world will show you
by adding methods anyway.
> Just focus on Collection classes and numbers.
>
> I like to ignore these as well.
I think this is a mistake. The collection classes are very important. They
are also great examples of well-designed Smalltalk classes.
-Ralph Johnson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20060501/fabdd164/attachment.htm
More information about the Squeak-dev
mailing list
|