Subclassing vs. Composing [was: Having brains again after being headless?]

Anthony Hannan ajh18 at cornell.edu
Sat Dec 14 17:16:36 UTC 2002


Tim Olson <tim at io.com> wrote:
> I can't remember if this was answered previously in this thread, but
> what are the reasons for having Interpreter be a subclass of
> ObjectMemory, as opposed to having an instance variable which is an
> ObjectMemory?

Because the VM code is translated to C which has no objects.  All
ObjectMemory and Interpreter variables become globals and sends to
'self' are intepreted as a regular function calls.
> 
> Personally, I use subclassing only when the subclass is clearly the same
> kind of thing as the parent class (with some slight behavior changes),
> and composition for everything else.  But I suppose I may be missing out
> on some benefits of subclassing.

No, your not.

Cheers,
Anthony



More information about the Squeak-dev mailing list