in reply to Is it a bad idea to subclass XML::LibXML ?
#code doesn't work
foreach my $node (@{$nodes}){
my $ele = new Foo($node);
# use ele as a wrapper for $node
}
#end code that doesn't work
In this example Foo is used to extend or adapt the functionality and interface of $node, but doesn't confuse the framework by adding additional subclasses. If you are trying to add additional behavior to $node you want to use something called the Decorator pattern. If you are just trying to simplify the interface or change it to meet you expectation you want to use something called the Adaptor pattern. Both of these patterns use composition. Using Composition over inheritance will generally simplify your design.Scott Walters has put together a great Perl patterns resource called http://perldesignpatterns.com/?/ and has created a great explanation of what patterns (a highly recommended read) are. The decorator pattern is discussed here and the adaptor pattern is discussed here. Based on your question I think one of these may help.
Cheers,
John
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Is it a bad idea to subclass XML::LibXML ?
by nenbrian (Acolyte) on May 09, 2004 at 05:45 UTC | |
by raptnor2 (Beadle) on May 13, 2004 at 01:43 UTC | |
by nenbrian (Acolyte) on May 18, 2004 at 23:13 UTC | |
by raptnor2 (Beadle) on May 19, 2004 at 02:31 UTC |