|Perl: the Markov chain saw|
Re: Modular Codeby tinman (Curate)
|on Jun 14, 2001 at 22:37 UTC||Need Help??|
In short: no, not exactly.. :o) I'll try to explain my grasp of the concepts as best as I can..
First of all, OOP is not *only* about reuse. Reuse is a good side effect of using objects, but there are other good effects too..
If you're doing a particular job over and over again, the first place I'd look is to move that code into a sub (subroutine)... Saves overhead, avoids duplicating code all over the place..
OOP deals more with concepts of modularization and abstraction.. Firstly, take the following example:
Objects can help you maintain state... to follow the same example:
In other words, what's happened here is that the explicit maintenance of a bank balance has been abstracted away from you.. The object maintains the state of the bank balance... Think of an object as a neat little package which contains all the variables and function calls you need to do a particular job..
As I understand your problem, if you just need to open a file frequently, then an OOP interface is probably overkill.. for your second question, if you want something like this:
then an object oriented interface looks nicer, but isn't really necessary... you could write it procedurally as: