On Thursday, July 24, 2003, at 08:49 AM, David Wheeler wrote:

On Wednesday, July 23, 2003, at 05:57 PM, chromatic wrote:

The first is a deeper question -- besides inheritance, there's delegation, aggregation, and reimplementation (think mock objects) that can make two classes have equivalent interfaces. I'd like some way to mark this equivalence *without* having to inherit from an abstract base class and I wish that interface equivalence were checked before inheritance, as per Luke's idea.

Sounds like you want Java-style "interfaces" to me.

No, I think Java interfaces are a kluge to get around copying a broken type system and the lack of multiple inheritance.


I don't want to litter both the caller and the callee with interface declarations that do nothing but say "this thing here understands the same methods as that thing there". The caller, fine -- that's the place it belongs.

If I have to modify the callee to do this, I've insufficient polymorphism.

Think of it this way. If you write Perl 5 code like this:

        sub some_method
        {
                my $self = shift;
                die "Bad object" unless ref $self = 'Some::Class';
                # do something useful...
        }

someone will have to change or override some_method() if he wants to subclass it. You could make his life a little easier by writing:

        sub some_method
        {
                my $self = shift;
                die "Bad object" unless $self->isa( 'Some::Class' );
                # do something useful...
        }

I'm suggesting to go the next step and let the code say, "Hey, if it acts like an instance of Some::Class, I don't care where it gets its behavior. I'll treat it like an instance of Some::Class." That's what I do with Class::ActsLike, and that's what I'd like to see here:

        sub some_method
        {
                my $self = shift;
                die "Bad object" unless $self->acts_like( 'Some::Class' );
                # do something useful...
        }

Now it doesn't care whether I've inherited, aggregated, delegated, or reimplemented. My argument is that it shouldn't have to care. It should only care that I've somehow promised that what I'm passing in behaves like it expects it to behave. How it does that is uninteresting.

-- c



Reply via email to