Perl Monk, Perl Meditation | |
PerlMonks |
Re: Re: A quick OO primer...by dragonchild (Archbishop) |
on Sep 11, 2001 at 17:21 UTC ( [id://111743]=note: print w/replies, xml ) | Need Help?? |
Frankly, I'd just use a hash. *grins* Call a spade a spade. Since you're writing the code, you know exactly how that hash is going to be used. If someone is stupid and violates the contract of that hash ("Don't assign to me cause I'm your configuration values!"), then any problems are their own fault.
Objects are supposed to be things that do stuff, not things that act as repositories. (Of course, there're exceptions to every rule, but it's a good starting point.) Now, there is a way to make a good configuration object. You just have to change the way you think about it. What you could do is pass the configuration object a filename. You, as the main program, wouldn't know how the configuration file is set up or what all the things it specifies are. Then, what your main program would do is ask the object if XXX is set to nnn, maybe by doing something like All the parsing of the config file, maybe even writing of a new config file, and everything that has to do with configuration would be encapsulated within this object. The trick is to get the interface right. Your main program doesn't want to know the exact values ... it just wants to know if it can do something based on an attribute's value. ------ Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
In Section
Seekers of Perl Wisdom
|
|