Piers wrote:
 
   > I'm kind of tempted to look at adding another pragma to go with 'use
   > base' along the lines of:
   > 
   >      use implements 'Interface';
   > 
   > Which is almost entirely like C<use base 'Interface'> but with
   > 'Interface' consisting of nothing but:
   > 
   > 
   >      package Interface;
   > 
   >      sub virtual_method;
   >      sub virtual_method2 (#prototype);
   >   
   >      ...
   > 
   >      1;

You and I must have been separated at birth, Piers.

Here's what I wrote to Nat just yesterday:


        There would be an C<interface> pragma or keyword (let's go
        with keyword) that creates pseudo-packages with which lexicals
        can be typed.

                interface Fetcher;

                sub fetch;

        Interface specifications can only contain subroutine (method)
        declarations, which describe what behaviours the interface requires.

        Lexicals typed into interfaces (as opposed to packages) only require
        that the objects assigned to them can satisfy the interface. I.e.
        they don't care about the class of the object, only what is C<can>
        do.

                my Fetcher $x;
                my Dog $spot;
                my NetSnarfer $z;

                $x = $z;        # ok because $z can fetch
                $x = $spot;     # ok because $spot can fetch
                $x->fetch();    # ok because Fetcher->can('fetch')
                $x->bark();     # not ok because ! Fetcher->can('bark')


        Interfaces might also act like pure abstract base classes when
        inherited, so that:

                package Dog;
                use base 'Fetcher';

        would cause a compile-time error if Dog failed to actually provide
        a C<fetch> method.


If you'd like to run with it, be my guest (but check with Nat first, in 
case he wants it).

Damian

Reply via email to