Introducing more meaning into inheritance

Leandro Caniglia caniglia at mate.dm.uba.ar
Mon Apr 27 17:25:53 UTC 1998


David Stes wrote:

>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

The problem here seems to be that while class Integer models each of the
elements in Z, classes as Group or Ring refer to sets, not to elements.

>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.

I've used this approach too. In math, you have two kind of objects: elements
and structures (objects in the sense of mathematical categories). For
example, you may consider the field of Algebraic Numbers and, on the other
hand, individual algebraic numbers as $\sqrt 2$. In Smalltalk, generally
speaking, it is straitforward to model elements but it is more dificult to
model structures. Still, it is possible to do that if you keep structures
appart from elements. As an example, consider the class AlgebraicNumber,
where instances are individual numbers. The role AlgebraicNumber plays in
the system is similar to that of Integer. It is clear that you need a class
for algebraic numbers because you have many diferent instances. But you
don't need a class for the field of algebraic numbers (over Q); it is rather
an instance of some other class. So you can model this field as an instance
of some class Field. I call this class AlgebraicAmbient.

>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!

In Smalltalk, I've used the concept of "Ambient" to recreate the structures.
For example, you can model all the objects found in Linear Algebra: tuples,
basis, subspaces, matrices, linear transformations, equations, etc. Doing
so, I faced the problem of how to model the ambient space where all these
objects live. Also I needed some knowledge about the scalars (are they a
field, a ring or what?). I solved the problem using Smalltalk classes as
LinearAmbient and AlgebraicAmbient. This is not the place to describe they
here but let me say a few words about them:

LinearAmbients model the linear spaces acting as the superset of linear
subspaces (k^n, M_n(k), End(V), etc.).  AlgebraicAmbients model the field of
scalars (Z, Q, Z_p, k(x), Algebraic Numbers, etc.). Following this approach,
if for example, V is a linear subspace in some LinearAmbient, you can easily
construct the LinearAmbient End(V) of V-endomorphisms. Also you can
construct ambients of tensor-products, direct sums, duals, etc. It is easy,
clear and useful and was made using simple Smalltalk concepts.

Of course, a lot of work must still be done. But mathematicians should
explore deeper the current posibilities of Smalltalk, since some problems
that seem to be in the paradigm are just design problems.

Saludos,
Leandro





More information about the Squeak-dev mailing list