I would go for option 1 (dependency injection).
Option 2 uses static methods, which, as already mentioned, simply prescribe global methods. And we all know that this is bad? is not it?
Option 3 is not my favorite because it is not enough OOP ;-), but serious: what if you (or the person using your code) want to change the format of the configuration file?
Option 4: global ...
Thus, basically my problems are with other options: testability, hard link, global.
So, option 1 is. I would also create an interface for the config class so that you can add another class for your configuration files at a later time. For instance. you (or someone else for that matter) want to use the XML files for configuration.
Another thing that I would change is private stuff. If someone wants to extend the class, he will not have access to variables in this way. My rule of thumb (not sure if everyone agrees with this, though) only makes the material private if you want people to have access to it (for example, it will change at some point). The danger of using private is that people will bypass it with hacks to do what they want.
Learn more about SOLID and see for more information.
Only my 2 cents.
source share