Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I think some perspective is required here. I agree that "can you do it? then do it" protocols are adding superfluous logic. However you do want to take different actions depending on what kind of thing you have. It doesn't make sense to have every object accept every possible message ever but ignore all but a small set of them (because it can't handle the rest) - does it? mvc was arguing to decrease coupling, but he also conceded that the ultimately independent object is one that has no methods and is ultimately useless. What you really want to do if you are concerned about purity and want to loosen coupling is having the conditional be implicit in the $token's class. See evolving an OO design for this principle. Loose coupling is achieved by removing the condition from the calling code altogether.

In the case in question, the correct approach would be to have a different class for every type of token, and to define a ->clean_up method for each of them. The one for a start tag would delete font attributes, in others it would be a no-op. Then, you just write:

while(my $token = $parser->get_token) { $token->clean_up; print $token->as_is; # possibly: # print $token->clean_up->as_is; }

Is that worth the effort? It depends on the scale of the project.

I would like to argue in favour of enforcing the difference.

That would necessitate "can you do it? then do it" for small scripts (which I believe are more readable for it). In large projects, it would be very helpful to have the strictness enforced as an extra debugging tool. If I mix up the types of objects at some point in the code, letting all of them accept any kind of message is not going to help me track down the error.

If inconvenience for small scripts is a concern (though that isn't what you were asking about), I would possibly add a strict => 0 option to the constructor.

Makeshifts last the longest.


In reply to Re: OO style question: how much information to hide? by Aristotle
in thread OO style question: how much information to hide? by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (10)
    As of 2014-07-22 21:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (129 votes), past polls