Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.kei.com!newsfeed.internetmci.com!psgrain!qiclab.scn.rain.com!slc.com!servio!news
From: cohenb@slc.com (Bruce Cohen)
Subject: Re: a Vector subclass goes where?
In-Reply-To: David N. Smith's message of 10 Nov 1995 14:24:58 GMT
Message-ID: <COHENB.95Nov14094102@topdog.slc.com>
Lines: 43
Sender: news@slc.com (USENET News)
Nntp-Posting-Host: topdog
Reply-To: cohenb@slc.com
Organization: GemStone Systems, Inc.
References: <47odg1$664@canton.charm.net> <47vnbq$tml@watnews2.watson.ibm.com>
Date: 14 Nov 1995 17:41:02 GMT

In article <47vnbq$tml@watnews2.watson.ibm.com> David N. Smith <dnsmith@watson.ibm.com> writes:

> Well, I share your unease. I wrote support for complex numbers
> (both polar and rectalinear) and ended up making Complex be a
> subclass of Object since they didn't really fit well elsewhere. 

Hmm ... I don't think I'd have made that choice.  When I've built
complex number packages (once a quick hack in Smalltalk, once in C++ to
extend the existing support), I've come down to wanting to easily
promote and reduce between complex, real, and rational numbers.  This is
much easier if they're all in a single hierarchy.

> Vectors are a bit different since they do act like arrays too. 
> (At least I assume by 'vector' you mean a single-dimensioned
> array of values, rather than a directional vector of 2 values
> (x,y) or 3 values (x,y,z)).

The problem again is that there are relationships (though not really
inheritance hierarchy relationships here) among real numbers, vectors,
and matrices.  It's nice if your system can express the fact that a
one-row matrix acts like a vector (though, of course there are some
interesting and subtle differences between that and a one-column
matrix).

From an implementation point of view, I favor the approach of designing
any aggregate object like an array or vector as a holder with an instVar
that holds the array of values.  This makes growing and shrinking the
array very easy (the way VisualWorks uses become: to change the size of
a collection is a classic example of why a holder is a winning
strategy).

I guess a lot of decisions have to be made based on what you plan to do
with the objects; if you get too concerned with uncommon usages or
potential, but currently unneeded enhancements, you can easily
overdesign.  There are a lot of cases of class library design projects,
both academic and commercial, that never saw the light of day because
the designers are *still* designing them.  (Mea culpa; I fight this
tendency in myself all the time.)
-- 
-----------------------------------------------------------------------------
Bruce Cohen, GemStone Systems, Inc.              |   email:  cohenb@slc.com
15400 NW Greenbrier Pkwy, Suite 280              |   phone: (503)690-3602
Beaverton, OR USA 97006                          |   fax: (503)629-8556
