Introducing more meaning into inheritance
David Stes
stes at mundivia.es
Mon Apr 27 07:31:58 UTC 1998
On Sun, 26 Apr 1998, Florin Mateoc wrote:
> Why not something like:
>
> Object
> Collection
> Bag
> Array
> ...
> Set
> Class
>
> so why isn't Class a Set ?
You have to be careful with this sort of reasoning, I believe. Let me
give some concrete examples (of my own experience).
I am a mathematician, algebraic geometry, in fact. I started designing a
few years ago (back then, as a student) a set of objects for computing
with polynomials.
I started out by trying to design a good interface.
My reasoning was rather formal I believe : I was following the path of
using concepts like "additive semimonoid", "abelian group", "partial
ordering", "division algebra", "integral domain" etc.etc. to
characterize my objects and the way the various arithmetical operations
worked.
However, I feel, after revising many times that interface, that there's
something more subtle going on, for classifying Smalltalk (or in my case:
Objective-C) Objects, than using classical, algebraic concepts.
There are rules, but the rules of the software engineering of a set of
classes, are not necessarily those of e.g. algebra as developed by e.g. a
Noether or a David Hilbert.
For example, I believe the following would NOT be a good inheritance
chain (but you may disagree) for Integer :
SemiGroup
AdditiveSemiGroup
SemiMonoid
Monoid
AdditiveMonoid
Group
AdditiveGroup (abelian)
...
Ring
IntegralDomain
Integer
(don't panic : I am sure it is not going to happen in Smalltalk!)
Nevertheless you *could* say "Integers" are an additive group and
multiplicativily closed for multiplication, so why is this not expressed
in the inheritance chain !?
I believe that your question about "why is Class not a subclass of Set"
!? is similar, after all.
After struggling a few years with classes like
"Integer-DegreeSparse-Recursive-VariableDense-Polynomial" as a subclass of
EuclideanDomain and result of some Polynomial constructing functor, I
just stopped doing it at that way, and I choose an interface centered
around objects with very *simple* names :
Polynomial, Term, Monomial, BigInt, Symbol etc.
Of course for the _algebra_ of this sort of thing, you still have to be
able to think in terms of "this is a noetherian ring" or "if I'll
construct polynomials and a quotient ring over that domain, I'll get zero
divisors etc."
It is just that you can IMHO not carry over those concepts literally to
an object oriented programming language. Well, there's quite a few
languages out there that still do it, so I suspect this posting will be
controversial!
David.
More information about the Squeak-dev
mailing list
|