[Newbies] Adding methods to Integers...

Ralph Johnson johnson at cs.uiuc.edu
Thu Apr 12 15:39:32 UTC 2007


It is fine to add methods to kernel classes like LargePositiveInteger.
 Just make sure you use new names, because you don't want to override
an inherited method by accident.

There are several problems with adding methods to existing classes.
One is when you override a method by accident.  To prevent this, pick
unique names for methods.  Another is when someone changes the class,
breaking your code.  you can run into this problem when you subclass a
kernel class, too.  It is not likely to happen in the near future, but
if you wait long enough, the class is likely to change.  Finally,
someone else might want to change the same class, and your changes
will conflict.

If you are writing code that you expect will last a long time and that
will be reused by many people, avoid changing kernel classes as much
as possible.  if you are writing a quick hack to see if you can do
something, do whatever seems easiest.

One of the big advantages of Smalltalk is that you can change
anything.  Changing system classes has the potential to increase the
cost of maintenance, but it definitely can reduce the cost of making
your system in the first place.

-Ralph Johnson


More information about the Beginners mailing list