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. All code is untested unless otherwise stated. In reply to Re: To use or not to use OO Perl
by gothic_mallard
|
|