New | BasicNew What is the Difference?

Stephan B. Wessels stephan.wessels at sdrc.com
Tue Jan 5 19:35:11 UTC 1999


John-Reed Maffeo wrote:

> > Most programmers will never use basicNew and basicNew:.  new is used
>
> The reason that I asked the question is found in the Form class methods
> extent:depth and extent:depth:bits. They use basicNew rather than new,
> and I couldn't figure out why.
>
> Form class inherits new and basicNew from Behavior, so it seems like
> it would be more appropriate for the methods to use new rather than
> basic new.

Looking at superclasses is not enough.  The Cursor class, which subclasses
from Form has overwritten new.  From here things get interesting...

Cursor class>>new calls
    self extent:fromArray:offset:
which it has also overridden.

Cursor class>>extent:fromArray:offset:
    calls super extent:fromArray:offset:
which would get picked up in Form.

Form class>>extent:fromArray:offset:
    calls (among other things) self extent:depth:

#extent:depth: is not defined on Cursor class so the method in Form would get
used
(incidently you would have to check every intermediate superclass between
Cursor and Form if there were any).

Form class>>extent:depth:
    calls self basicNew.

If it were to call #new (instead of basicNew) you would be right back up at
Cursor class>>new
which would loop of course.

That's one of the trip points to refactoring and simplification.  You need to
look up and down the hierarchy.

This might seem a bit confusing and we can probably (amongst all the mail list
readers) come up with a clearer example
if this doesn't make sense to you.

have fun...

  - Steve





More information about the Squeak-dev mailing list