in reply to Re: Re: Re: Class::Interface -- isa() Considered Harmful
in thread Class::Interface -- isa() Considered Harmful
Since both you and perrin have responded among similar lines, it seems that my examples are unclear and aren't communicating very well. Let me address your points in order and see if I can clear up my intent.
My goal is twofold:
In other words, I don't want this:
package A::Class; sub some_method { my ($self, $object) = @_; die "Object is not what I expect" unless UNIVERSAL::isa( $object, 'Some::Class' ); $object->some_other_method(); $object->some_method_or_other(); }
That unnecessarily dictates that $object has to inherit from Some::Class, or at least fake up enough so that it can fool UNIVERSAL::isa(). Consider a test case:
use Test::More 'no_plan'; use Test::MockObject; my $mock = Test::MockObject->new(); use_ok( 'A::Class' ); my $a = A::Class->new(); isa_ok( $a, 'A::Class' ); $mock->set_true( 'some_other_method' ) ->set_true( 'some_method_or_other' ); $a->some_method( $mock );
That dies, unnecessarily, because Test::MockObject does not subclass Some::Class. That's not what I want to express, either.
What I really want to express is that $object, whatever it is, ought to act like a Some::Class object. If it inherits from Some::Class, that's fine. If it delegates to a Some::Class object, that's fine. If it contains a Some::Class object, that's fine. If it simply conforms to the Some::Class interface, that's fine.
I don't think "reworking the object model" to make the other three possibilities fit into the inheritance scheme is the right approach. I think the interface approach is more general and, if implemented correctly, can handle all four possibilities easily.
I do think my examples were unclear though, and apologize for the confusion they caused.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Re: Re: Class::Interface -- isa() Considered Harmful
by djantzen (Priest) on Jan 16, 2003 at 21:17 UTC |