[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: OO should break when broken (was re: the benefits of immutability)
- To: address@hidden
- Subject: Re: OO should break when broken (was re: the benefits of immutability)
- From: "Michael St . Hippolyte" <address@hidden>
- Date: Tue, 2 Sep 2003 16:55:02 -0400
- In-reply-to: <20030902144822.B30589@localhost.inet>; from email@example.com on Tue, Sep 02, 2003 at 14:48:22 -0400
- References: <20030902144822.B30589@localhost.inet>
- Sender: address@hidden
On 2003.09.01 08:59 firstname.lastname@example.org wrote:
> 1. Derive the subtype relations between the types Real, Number, Complex,
> and Integer?
Even this classic example can defy expectations. In Bento I decided to
support parametric polymorphism through the type system, with syntax
which allows an object to pick its implementation superclass at runtime,
depending on its parameters. I was amazed to find out that this made
it as easy to use subclassing to generalize as to specialize.
Polymorphic supertyping lets you define a subclass which is effectively
a union of several types. With such syntax it's easy to model a general
object such as Number as the polymorphic subclass of a range of specific
numeric types (e.g. Integer, Real and Complex), inheriting the value of
whichever superclass is selected based on an examination of parameter
types at runtime.
The value of this approach is that your generalization can be tailor-made
to suit your needs; one program's idea of a generalized number may be
different than another's.
Another way to think of it is to consider subclassing as the direction
of dependency, not specialization. Conventionally, subclassing is used
to define special types as refinements of general types, but in some
cases it may make more sense to define a generalized type in terms of
special types. The result is a much more dynamic object hierarchy --
one which postpones the decision of where to inherit an object's
implementation from until it's actually needed.
Michael St. Hippolyte