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

Multiple classifications of an object

From:
David Whipp
Date:
June 25, 2001 11:45
Subject:
Multiple classifications of an object
Message ID:
000001c0fda6$d0a86830$926464c4@intranet.fastchip.com
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.
--
Dave Whipp, Senior Verification Engineer,
Fast-Chip inc., 950 Kifer Rd, Sunnyvale, CA. 94086
tel: 408 523 8071; http://www.fast-chip.com
Opinions my own; statements of fact may be in error. 
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About