Skip to main content
deleted 148 characters in body
Source Link
user619818
  • 1.8k
  • 2
  • 15
  • 24

I have a large project with a driver part and about 5 libraries doing various associated tasks. Many of the libraries require access to 'global' configuration data which is read from a database at startup by the driver code. By driver I just mean the part which contains the main function.

My idea on how to handle this was to create a config class with a static method to get the config items. Is this the best approach? How else could this be achieved?

eg:

class config { public: static get_item(key); private: static values; }; 

The class itself would not be static so each code component using it would create its own instance of the class, but I can't see a way round that. IsIs singleton design appropriate here?

I have a large project with a driver part and about 5 libraries doing various associated tasks. Many of the libraries require access to 'global' configuration data which is read from a database at startup by the driver code. By driver I just mean the part which contains the main function.

My idea on how to handle this was to create a config class with a static method to get the config items. Is this the best approach? How else could this be achieved?

eg:

class config { public: static get_item(key); private: static values; }; 

The class itself would not be static so each code component using it would create its own instance of the class, but I can't see a way round that. Is singleton design appropriate here?

I have a large project with a driver part and about 5 libraries doing various associated tasks. Many of the libraries require access to 'global' configuration data which is read from a database at startup by the driver code. By driver I just mean the part which contains the main function.

My idea on how to handle this was to create a config class with a static method to get the config items. Is this the best approach? How else could this be achieved?

eg:

class config { public: static get_item(key); private: static values; }; 

Is singleton design appropriate here?

Source Link
user619818
  • 1.8k
  • 2
  • 15
  • 24

Best practice for creating a 'global' config class used by numerous components

I have a large project with a driver part and about 5 libraries doing various associated tasks. Many of the libraries require access to 'global' configuration data which is read from a database at startup by the driver code. By driver I just mean the part which contains the main function.

My idea on how to handle this was to create a config class with a static method to get the config items. Is this the best approach? How else could this be achieved?

eg:

class config { public: static get_item(key); private: static values; }; 

The class itself would not be static so each code component using it would create its own instance of the class, but I can't see a way round that. Is singleton design appropriate here?