A simple change of the Actions variable by plugging in a different "behavior container" causes a bank-switch of those behaviors to a new motif. I forget the "gang of four" pattern for this, but it's one of those. {grin}package Elf; sub named { my $class = shift; bless { Name => shift; Actions => Elf::Live::, Has => {}, }, $class; } sub die { shift->{Actions} = Elf::Dead::; } sub can_attack { # delegate to actions shift->{Actions}->can_attack(@_); } sub enemy_of { shift->{Actions}->enemy_of(@_); } package Elf::Live; sub can_attack { ... } sub enemy_of { ... } package Elf::Dead; sub can_attack { ... } sub enemy_of { ... }
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
In reply to •Re: Re: ?Re: Change the parent of an instance
by merlyn
in thread Change the parent of an instance
by muba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |