On Thursday, October 3, 2002, at 04:25  PM, Michael G Schwern wrote:

> On Thu, Oct 03, 2002 at 03:54:09PM -0700, Michael Lazzaro wrote:
>>      I have no *good* syntax proposals for this, I don't think I've ever
>>      seen the problem solved with syntax that I really ever liked.
>
> Class::Delegation?

Yeah, it's one of the best I've seen: it makes sense, does everything I 
want, and is easy to explain even to newbies.  The perl5 hash-based 
syntax is still pretty scary, tho.

Dunno, I keep wishing for something that's a one-liner for simple 
cases.  I guess something like:
        
        # $.data_manager receives all method calls for which
        # it has a matching public interface.
        
        class DataSnippet {
                attr $data_manager is DataManager receives ( -ALL );
        }
        
        # alternative syntax, also useful on a method-by-method basis...
        # Note that if steer() has an implementation, it's dispatched there 
too.
        
        class Car is interface {
                attr $left_front_wheel;
                attr $right_front_wheel;
                ...
                
                method steer ( ... ) is dispatched( $left_front_wheel, 
$right_front_wheel ) { ... };
        }

Incidentally, I think the Car above is an example of why it might be ok 
to allow attributes in interfaces.  (I would definitely argue it's ok 
to give default method implementations in interfaces.  You don't have 
to if you don't believe in it, but hey, some people prefer it.)  You're 
basically saying that the interface attaches these named attribs to 
anything that use it.  It usually isn't considered proper, but I don't 
know if it's evil enough to explicitly disallow.

The biggest problem I see with interface attribs myself is 
implementational, not philosophical; if you've got attribs being 
assembled from multiple interfaces, it makes implementation of 
subclasses even more difficult to optimize.  (Of course, we already 
have multiple inheritance, so that ship's probably long sailed already.)

MikeL

Reply via email to