[QUANTITY] : class design complexity philosophy (Was: Re: [QUANTIT] Use-cases, role in larger scheme)
Brian Thomas
brian.thomas at gsfc.nasa.gov
Mon Nov 17 08:17:02 PST 2003
On Monday 17 November 2003 10:48 am, David Berry wrote:
> I suppose there are two approaches. One would be to define a separate
> class for each combination of components. If a basic Quantity was simply
> an N-d array (or similar structure), we could define classes
> QuantityWithUnits, QuantityWithWCS, QuantityWithUnitsAndWcs, etc. The
> other approach is to say that the Quantity class encapsulates all
> these extra components, but that any of these components may be null.
>
> I think the second approach would be the easiest and most flexible in the
> long run.
I agree with this, and an additional comment on why its "better": you
create an API which is relatively simple to use.
Creating an API via the first method leads to a "class explosion" which is
difficult for the programmer to deal with. ("which class is best for my code?"
+ needing big switches which attempt to determine the actual inheritance
of the class you have, ex.:
void someMethod (QuantityInterface Q) {
if( Q instanceOf QuantityWithWCS) then {
....
} else if ( Q instanceOf QuantityWithUnits) then {
...
}
}
Of course, there are limits on the second method as well, as I'm sure Pat will
point out. You can't make all classes too powerfull, or its just as unusable
for the programmer who is trying to implement the model. I think a reasonable
dividing line is asking the question, "what do all quantities need to tell us?"
If they are numbers, then we reasonably need to know the dimensionality, units,
value and data type *every time* we use them *even if* these quantities are
dimensionless, or unitless, or valueless or some simple type like integers
as that *is* information that impacts the scientific value of the quantity too
(even though it is technically "absent").
Regards,
=b.t.
--
* Dr. Brian Thomas
* Code 630.1
* Goddard Space Flight Center NASA
* fax: (301) 286-1775
* phone: (301) 286-6128
More information about the dm
mailing list