Let's say that I have classes M, A, B, C. M is the main class of my application (that is, the one that performs most of the job) and has this structure
class M { public:
Basically I create an instance m of class M, and I want to install my configuration object, say by reading it from a file. The configuration object is not something special, it can be a protocol buffer or a simple structure.
Now I want a, b and c to be able to access the configuration object, because there are some global settings that they need. These settings are global, they do not change and are the same for each instance of A, B and C (and M). What I am doing now has a static field in each class A, B, and C, and I set up a copy of the configuration object for each instance of these classes. I do not want these classes to know about M. Is this the best solution? Should I think of a global configuration variable?
source share