I don't doubt that in certain circumstances Fowler has found this to be a worthwhile reason for refactoring some code.
My issue with the example is that it is much simpler than the code that likely called for the refactoring in question. Case studies are nearly always favorable to contrived and overly simplistic examples, but that is just my opinion. In this particular case, though, I think the contrived example Fowler provided was too simple and would, in many places, be used as a counterexample.
As you've assured me that you're not stating these exercises as absolutes, let me assure you that I don't mean to discredit the examples entirely. I'm just pointing out where I think they are flawed and where I think Perl could be used in a more Perlish way.
As for the base price being factored out separately to remove bugs, unless the base price changes often, I'd rather see it spelled as:
$self->{'_hase_price'};
if that's a concern. The base price (extended price before discount) is not going to change any more often than the quantity of units or the price per unit, which were both considered to be object data directly. In fact, the base price would change if either of those did. Again, this is a weakness of the example itself and not of the point the example was used to make or your post.
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.