SPUG: OO Perl conundrum

Dean Hudson dean at ero.com
Mon Jun 11 20:55:51 CDT 2001

On Mon, Jun 11, 2001 at 03:45:50PM -0700, Richard Anderson wrote:
> package HTTP::WebTest;
> ...
> {
>     package PluginHelper;
>     ...
>    package Plugins;
>    use HTTP::WebTest;
>    ...
> }
>  ...
> This seems like a fairly non-standard use of OO Perl.  Would this be better
> done by subclassing HTTP::WebTest and making PluginHelper and Plugins
> subclasses of the new subclass be better? Or is there some simpler approach?

It seems to me that inheritance is not the correct relationship
between these things; composition is prolly what you're looking for
(ie an HTTP::WebTest object HAS one or more HTTP::WebTest::Plugins.)
You can keep track of them via an array in your HTTP::WebTest

Then you could require that a HTTP::WebTest::Plugin object implement a
particular method (say test()) which implements the test that you want
the plug-in to handle. After running your standard tests you iterate
over your array of plug-in objects and call their test() methods,
passing them the web page to be tested.

Does that make any sense? I'm not familiar with the module at all, and
I'm also not sure where PluginHelper fits in (I'm not sure what it
does) so I could be off base. But usually composition is a more
appropriate relationship than inheritance. 


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/

More information about the spug-list mailing list