I have the following issue:
I have a config object, highly specialized with no dependecy on anything. The main application engine uses it to initialize itself. The main engine also uses a global function which is used in several locations to translate an alias/handle into it's full form before actual processing.
I have just changed the architecture and the need has risen for me to use that very global function inside the config object. I'm shy to do so because I like keeping things simple and inpedenent of others.
Should I:
1) Just call the global explicitly (what happens if I change the name or need to add more namespace)???
2) Pass the function to the config object (through ctor) and have the config object use it as a callback
The latter offers the greatest flexibility, because I have a tecndancy to refactor code like crazy, especially changing function names, etc as better names come to mind. I also may one day wish to throw that function into an object/class (right now it's fine as a global) passing a function callback is an easy way to avoid having to conduct a Search and Replace whenever the namespace changes.
Go with number two or is there a different approach which would yield greater benefits?
If you decide to answer with anything other than #2 be verbose and obvious, clearly indicating pros and cons.
Edit: I'm just analyzing my architecture and thinking...there may be a requirement again in the future to provide a specialized object a callback functions. Different objects and more importantly, different callbacks. I always [s]try[/s] and keep any global initialization code, variables, function calls, etc inside the index.php file.
The engine object as we speak has the hardcoded global function named (as it's passed to config object) explicitly as a string passed to the config ctor(). If there are other objects, either composites of engine class, etc...that may require callbacks in the future I can see this technique being messy in a constantly changing namespace such as my own.
I'm wondering if it would make much sense to have a registry, specifically dedicated to global callbacks, so any namespace change can be applied inside my init.php once instead of having to grep the source and find each instance. Like a service locator almost, but not really...
Any related patterns or ideas or suggestions as to how to implement a more robust system?
Cheers