The problem there is that you've hardwired the Utility class's name into your class. Suppose you want to subclass Foo to use a different UtilityClass (or a subclass of it), with the hardwiring you have in place you have to override
all the methods that make calls to the utility class.
At the very least you should wrap the Utility classname in a method, so your code becomes:
package Foo;
use UtilityClass;
sub helper { 'UtilityClass' }
sub bubbles {
...
$self->helper->buttercup();
...
}
Et voila! you'll only have to change the utility class name at two points in your subclass; no need to override.
Actually, I wonder if you couldn't use the Exporter to implement something like a ruby mixin.
package UtilityClass;
use base 'Exporter';
@EXPORT = qw/buttercup/;
sub buttercup {
my $self = shift; # $self is *not* a 'UtilityClass';
...
}
You know, I'm not sure whether that's a good idea, or a barking mad one...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.