Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I do actually use OO quite a lot when I'm building modules. I'll be first to admit that I'm perhaps guilty of looking to the OO option first as I prefer the style, but I also (I believe) know those times when a vanilla module would fit the bill just as well.

As to when to use OO it normally follows that I do it in the situations where I can visualise the problem as an object.

When I built my email module it seemed natural to me that it should be an object - an email is a "thing" (read: object) that has properties associated with it ("to" address, body text et al) and methods that apply ("create email","add attachment","send" etc).

The email is the central object around which it hinges.

On the flip side, consider the example of the Math::Trig module. Where would the object be? The input value? - but there may be more than one. The result? - but until it runs there isn't one. Instead it creates a set of functions that can be used more generally.

To your second question - I wouldn't say that OO is "prefered". It's all very much dependant on the application concerned - it's quite possible that in one context using OO is the way to go, whereas in another on the same problem it may be viewed as overkill.

This is just my view, but I hope this helps.

--- Jay

All code is untested unless otherwise stated.


In reply to Re: To use or not to use OO Perl by gothic_mallard
in thread To use or not to use OO Perl by monkfan

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found