On Mon, Jun 25, 2001 at 11:44:06AM -0700, David Whipp wrote:
> When you blass an object in Perl, you give it exactly
> one type. The @ISA variable allows that type to refer
> to many other classes as the inheritance tree. @ISA
> is a list, but ref($obj) isn't. This means that you
> sometimes have to create a lot of useless classes to
> work around this limitation.
...
> Can anyone see any problems with making C<bless> and
> C<ref> work with lists? C<isa> is not effected. 

I don't know if this is the answer.  Lemme dig out "Design
Patterns"...  okay, the Bridge pattern addresses this.  If you look at
Male and Female to be implementations of the Person class, rather than
subclasses, things slip in easier.  I'm not going to go into the
details, look at "Design Patterns" Gamma, Helm, Johnson and Vlissides
pp 151-161

Another way to address this is delegation instead of inheritance.
Male ISA Person and Female ISA Person, but Employee is not.  Instead,
Employee HASA Person.  Each Employee object contains a Person object.
So, for example, you might do this...

        package Employee;
        sub name {
            my $self = shift;
            $self->{_Person}->name(@_);
        }

which delegates any calls to Employee->name off to Person->name.
That way, Employee doesn't have to know if the Person is Male or
Female.

There are lots of tricks you can do with autoloaders and such to make
this process much easier.  Delegation is really good for handling
things that inheritance makes complicated.


> We might want some magic to ensure 'ref($foo) eq "bar"' still works
> as expected.

Oooh, I've had to do things like that in the past, usually to keep
backwards compatibility with a wonky interface.  A function which
returns an overloaded string that can equal many things.
Alternatively, it returns a superimposed scalar. ;) Not something you
want to have to do by choice.

-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <[EMAIL PROTECTED]>       Kwalitee Is Job One
Our business in life is not to succeed but to continue to fail in high spirits.
                -- Robert Louis Stevenson

Reply via email to