At 1:24 PM +0100 11/10/06, TSa wrote:
HaloO,

I wonder how an object can change its type without loosing its
identity. Consider two types Rectangle and Polygon with Rectangle
a subtype of Polygon. Now if there is a method add_vertex in the
Polygon type, calling it on a Rectangle warps the object out of
the Rectangle type into a Polygon with five vertices. How does
the implementation of Rectangle::add_vertex achieve this type
warp?

For a subset type the warping might occur automatically because
the where clause fails:

  subset Rectangle of Polygon where { .num_vertices == 4 && ... }

A class type might just call self.bless(Polygon) after adapting
the internal representation. But how does an object loose a role?
Should there be an undoes or strip operator that does the inverse
of runtime role composition?

What is the point of declaring a type as Rectangle, with those limitations, if you are going to mutate it into not being a Rectangle.

Calling add_vertex() on a mutating Rectangle should necessarily die.

The better approach would be one of:

1. The user explicitly casts the Rectangle into a Polygon, and then invokes the add_vertex() on it.

2. The Polygon class is immutable, and add_vertex() will create and return a new Polygon object with those properties, and the original is still the Rectangle.

-- Darren Duncan

Reply via email to