princepawn has asked for the wisdom of the Perl Monks concerning the following question:
package X; sub A { " base class implementation" } sub B { " base class implementation" } 1; package Y; @ISA (X); # Let's use A() from the base class sub B { "local implementation" }
However, based on a command line option, it is sometimes necessary for objects of Y to do something special instead of X::A(). I think I just arrived at the solution to my problem.
What I should do is this:
sub Y::A { unless ($getopt{special_case}) { $self->SUPER::A(); return; } # do the stuff based on the command line arg if # the special case was chosen from the cmd line. }
I was breaking out in a sweat here, thinking I was going to have to add subroutines to package Y dynamically at runtime based on cmdline args. Phew.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Best Method of Object-Oriented Behavior Addition?
by merlyn (Sage) on Sep 29, 2000 at 17:36 UTC | |
by jplindstrom (Monsignor) on Sep 30, 2000 at 18:25 UTC | |
|
Re: Best Method of Object-Oriented Behavior Addition?
by japhy (Canon) on Sep 29, 2000 at 18:47 UTC | |
|
Re: Best Method of Object-Oriented Behavior Addition?
by Fastolfe (Vicar) on Sep 29, 2000 at 19:58 UTC | |
|
Re: Best Method of Object-Oriented Behavior Addition?
by jreades (Friar) on Sep 29, 2000 at 19:25 UTC | |
|
Re: Best Method of Object-Oriented Behavior Addition?
by AgentM (Curate) on Sep 29, 2000 at 18:49 UTC | |
by japhy (Canon) on Sep 29, 2000 at 22:00 UTC |