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

Re: Multiple classifications of an object

From:
Damian Conway
Date:
June 25, 2001 13:16
Subject:
Re: Multiple classifications of an object
Message ID:
200106252016.GAA69231@indy05.csse.monash.edu.au
   > >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";
		$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



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