Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

•Re: Re: ?Re: Change the parent of an instance

by merlyn (Sage)
on May 11, 2004 at 18:43 UTC ( #352540=note: print w/replies, xml ) Need Help??


in reply to Re: ?Re: Change the parent of an instance
in thread Change the parent of an instance

No, I mean you plug it like this:
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 { ... }
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}

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Re: ?Re: Change the parent of an instance
by Fletch (Chancellor) on May 11, 2004 at 20:04 UTC
Re: ?Re: Re: ?Re: Change the parent of an instance
by muba (Priest) on May 11, 2004 at 18:47 UTC
    Ah! Now I see!

    I think it's the best idea I've seen so far, assuming re-blessing really sucks. I'll have a look at it (a big re-style of the code is now required but it's worth it).

    Just for my information, could you please tell me the disadvanteges of re-blessing?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://352540]
help
Chatterbox?
[erix]: Nancy-Bari: 1320 km ... He'll need some time :)
[LanX]: he was "meating" Italian monks oO?
[erix]: then again, there are people who do 10 full triathlons on 10 consecutive days, so it must be doable
choroba's friend has done the Pacific Crest Trail, it's 4200 km
LanX Ladies and gentlemen: due to shortages of "Body of Christ" we have to resort to Body of Monks ...
LanX ... buon appetito!

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2017-12-13 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (369 votes). Check out past polls.

    Notices?