Jon A. Cruz wrote:
In one sense we can view the preferences as a global variable, which is slightly evil. However, once we change code to have its values pushed in, instead of having each little sub-bit of code poll the preferences thing, then we can switch even more easily.
The preferences being global is not a bad thing, since we want consistent behavior. There is exactly zero use for multiple Preferences objects. Similarly, using the "global" clipboard is not bad. I think you're taking the "globals are evil" approach too far.
The only problem with the prefs now is that nearly everything depends on them, so it's hard to come up with the correct link order and it would be hard to separate out libraries to use for other apps. However, the first point would be mooted if we linked the executable from single object files rather than a multitude of static libraries, because then the linker would resolve back-references and the link order wouldn't matter.
I think one pattern I've heard used is "dependency injection". Many aspects of that address what we're seeing in the code now.
This is essentially what I wanted to do when I proposed GConf.
Regards, Krzysztof Kosiński