TSa wrote:
HaloO,

I want to propose a little addition to subset type definitions.
They should get an implementation body like classes and roles.
This is useful to add methods to the type. Here is my Rectangle
example from the 'how to change the type of objects' thread.

# @.points contains Point objects
subset Rectangle of Polygon where { [EMAIL PROTECTED] == 4 && ...}
{
    # new methods
    method width  { return (@.points[1] - @.points[0]).abs }
    method height { return (@.points[2] - @.points[1]).abs }

    # overridden method from Polygon
    method area { return self.width * self.height }
}

As opposed to

 subset Rectangle of class {
   is Polygon;
   method width { ... }
   method height { ... }
   ...
 } where { [EMAIL PROTECTED] == 4 && ...}

?

Anonymous classes are useful things.

BTW, can a subset definition also be based on a role?

IMHO, there's no reason not to allow this.  About the only time that
something should be permitted for classes but not roles is when it
deals with object management.

--
Jonathan "Dataweaver" Lang

Reply via email to