in reply to Power of single objects
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Power of single objects
by princepawn (Parson) on Oct 19, 2000 at 19:49 UTC | |
by Fastolfe (Vicar) on Oct 19, 2000 at 22:16 UTC |