Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: A quick OO primer...

by synapse0 (Pilgrim)
on Sep 11, 2001 at 03:08 UTC ( #111625=note: print w/replies, xml ) Need Help??


in reply to A quick OO primer...
in thread Object insanity and data hiding

Thanks for the reply.. I'm trying to sort out how directly your statements describe my code. I think I have a competent idea of OO, but since i've never had anyone poke around my code and point things out, I dunno for sure.

All you are doing is associating functions with a hash, then unnecessarily abstracting a function call over every access to that hash

Well, in this particular case, that's precisely what this object is supposed to do. Really, it's just a config file regurgitator. Is there another way you handle something like this, where the object is there mostly to access specific data, and not make any changes to that data?

I hope your go/othello project is going well..
-Syn0

Replies are listed 'Best First'.
Re: Re: A quick OO primer...
by dragonchild (Archbishop) on Sep 11, 2001 at 17:21 UTC
    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

    if ($config->isSet('XXX', nnn)) { # Do something here } else { # Do something else here }
    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.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://111625]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2023-01-28 06:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?