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

Re: Multiple classifications of an object

Damian Conway
June 25, 2001 13:16
Re: Multiple classifications of an object
Message ID:
   > >What's wrong with multiple inheritance?
   > Nothing, but he wants MI on a per-object basis, rather than a per-class 
   > basis, presumably to avoid having to create a zillion classes who's sole 
   > purpose in life is to have an @ISA array.
   > Sounds sensible, and worth sending past Damian.

It's certainly not unreasonable, though it doesn't mesh perfectly with
Perl's OO model. The easy solution (available in Perl 5 too) is to
autogenerate the interim MI-ing classes as needed:

	my $next = "a";
	sub multibless {
		my ($ref, @classes) = @_;
		my $MIclass = "_MI_class_$next";
		@{$MIclass."::ISA"} = @classes;
		bless $ref, $MIclass;

	# and later:

	my $schimmer = multibless {}, qw(Dessert_Topping Floor_Wax);

But one could also imagine that Perl 6 might allow individual objects to
have an C<ISA> property that pre-empted their class's C<@ISA> array.

Damian Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About