On Fri, Apr 30, 2004 at 11:14:55AM +0200, Aldo Calpini wrote:
> let's suppose I want to build a class that keeps track of the objects it
> creates.
>
> let's suppose that I want this class to be the base for a variety of
> classes.
>
> let's suppose that I decide, rather than fiddling with the default
> constructor, to wrap it up.
>
> something like:
>
> class Animal {
> our @.zoo;
> &new.wrap( {
> my @results = call();
> push(@.zoo, @results[0]);
> return @results;
> } );
> }
> class Lion is Animal { ... }
> class Tiger is Animal { ... }
> class Panther is Animal { ... }
>
> my $simba = Lion.new();
> my $shere_khan = Tiger.new();
> my $bagheera = Panther.new();
>
> my @all = @Animal::zoo;
> # @all should contain ($simba, $shere_khan, $bagheera);
>
> will the above code work as expected, or is there something I've
> overlooked?
Perl6 seems already to have plenty of mechanisms like delegation
to dynamically change the behavior of a class. So, probably,
wrappers is a mechanism more adapted to extend method behavior at
run-time by entities that don't have access to the internals of a
class.
Comments?
--
stef
>
> cheers,
> Aldo