Personally, I feel that some modules nowadays are trying to use objects because it's "cool", even though the module would be better off being used in a functional manner.

If a module doesn't need to keep track of state information at all between "methods"/functions, you generally don't want to use an object-oriented approach. If it's possible/likely that the user (the developer) will want to create multiple objects/sets of state information and manipulate each set individually, an object-oriented approach is pretty much a must.

For stuff in between, though, don't underestimate the value of passing arguments to simple functions, exported by your module. If you feel that your module will easist to use in a functional capacity, but you'd still like to offer the developer the ability to create objects, why not just write your module to support both methods (a la CGI.pm)?

For example, DBI needs to use objects. Without them, we would be unnecessarily preventing the developer from working with two databases at the same time. Array::Compare, however, does not need to use objects (it does!). Why do we need to instantiate a "comparator" object to perform our array comparisons? A function, with perhaps optional arguments, would be a lot easier to use and read. Plus, it would allow us to use function prototypes if we felt the need (a plus in Array::Compare's case, for instance).

So don't jump on the OO train just because it's a nifty way of doing things. If your code would benefit functionally from using objects, or you have a need to keep track of isolated state information, fine, but weigh your module's usability against power and try to look at both ends of the spectrum.


In reply to RE: Power of single objects by Fastolfe
in thread Power of single objects by nop

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!
  • 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:
    & &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.