develooper Front page | perl.perl6.language | Postings from June 2001

Multiple classifications of an object

David Whipp
June 25, 2001 11:45
Multiple classifications of an object
Message ID:
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.

A simple example: Imagine you have a class "Person".
A Person can be Male or Female. Thats one set of
subclasses. But a Person can also be Employed or
Unemployed. So I might want to say

   bless $self, qw(Employed Male);

In Perl5 I am forced to create 4 new classes:
Employed_Male, Employed_Female, Unemployed_Male,
Unemployed_Female. The combinatorial explosion can,
well, explode! The other standard solution is to
add a "Person has-a Employment_Status" relationship,
but that doesn't feel much better. Its just another
way of programming round a weakness in the object
models of most mainstream languages

Can anyone see any problems with making C<bless> and
C<ref> work with lists? C<isa> is not effected. We
might want some magic to ensure 'ref($foo) eq "bar"'
still works as expected.

Dave Whipp, Senior Verification Engineer,
Fast-Chip inc., 950 Kifer Rd, Sunnyvale, CA. 94086
tel: 408 523 8071;
Opinions my own; statements of fact may be in error. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About