I've looked around the web & can't find much on to help me out here, hoping you guys could shed some light.
I have a bit of a perl OO setup that looks like this -
Global has basic functions that loads info from a config file such as database connection info, username/passwords, path information etc.
The subclasses Security & Database use this loaded info for various purposes (eg connecting to the database!!)
I create an object for at least Security & Database to keep their functionality separate & clear, and even instantiate Global to get at the loaded path stuff.
The "problem" I'm having is each of these objects naturally reload the data from the server's HDD when they are invoked (the method is called from the constructor), so there's extra overhead there I'd like to eliminate. Its not bad, and certainly not noticeable at the moment, but I think its just bad form =)
I'm thinking it would be nice if I can have static variables across the 'Global' class (& subclasses?), such that any other instances can access the already loaded settings - ???
Is this possible / practical?
Are there any suggestions for a better setup?
I'm thinking an alternative is to pull Security & Database away from Global and have them as top-level classes in themselves, and simply require a handle to a Global object to be passed to it in the constructor ??
Actually as I write this I think that method will be many times better, but I'll post this question anyway to hear any suggestions & see if static variables are possible, for future projects & other curious programmers.
I'll split the points amongst some of the most creative & informative replies.