rvosa has asked for the wisdom of the Perl Monks concerning the following question:
Also, I want this Listable::insert method to have the following properties:$tree->insert($node); #works $matrix->insert($datum); #works $trees->insert($node); #error: $trees object can't contain $node $matrix->insert($node); #error: $matrix object can't contain $node
The downside of this is that every insertion involves two method calls and a string comparison. Also, it feels a bit hokey, I think.sub insert { my ( $self, $obj_to_insert ) = @_; if ( $self->container_type eq $obj_to_insert->container ) { push(@{$self}, $obj_to_insert); } else { die "I can't hold that object!"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "polymorphism" hack: nuts or wise?
by Ovid (Cardinal) on Aug 26, 2005 at 17:37 UTC | |
|
Re: "polymorphism" hack: nuts or wise?
by merlyn (Sage) on Aug 26, 2005 at 17:54 UTC | |
|
Re: "polymorphism" hack: nuts or wise?
by exussum0 (Vicar) on Aug 26, 2005 at 17:44 UTC | |
by Ovid (Cardinal) on Aug 26, 2005 at 18:01 UTC | |
by perrin (Chancellor) on Aug 26, 2005 at 18:16 UTC | |
by chromatic (Archbishop) on Aug 26, 2005 at 19:39 UTC | |
by Ovid (Cardinal) on Aug 26, 2005 at 19:00 UTC | |
by exussum0 (Vicar) on Aug 26, 2005 at 18:10 UTC | |
by rvosa (Curate) on Aug 28, 2005 at 11:46 UTC | |
|
Re: "polymorphism" hack: nuts or wise?
by Tanktalus (Canon) on Aug 26, 2005 at 17:49 UTC | |
|
Re: "polymorphism" hack: nuts or wise?
by dragonchild (Archbishop) on Aug 27, 2005 at 02:32 UTC | |
by rvosa (Curate) on Aug 30, 2005 at 12:40 UTC | |
|
Re: "polymorphism" hack: nuts or wise?
by sgifford (Prior) on Aug 26, 2005 at 17:52 UTC | |
by rvosa (Curate) on Aug 30, 2005 at 12:27 UTC |