backintime icon indicating copy to clipboard operation
backintime copied to clipboard

Refactoring and improvement: Config class is now a singleton

Open buhtz opened this issue 3 years ago • 0 comments

As discussed the class config.Config now acts like a singleton. No matter that there are a lot of possible variants to implement the singleton design patter in Python I choose a pragmatic one, that is IMHO easy to understand for newbies, using less lines and is easy to maintain.

  • Create an instance as usual via config.Config()
  • If an instance is still there this will raise an Exception.
  • Get an existing instance via config.Config.instance()
  • This also will raise an Exception if no instance is there.

From an academic point of view this may not fulfill all aspects of the singleton pattern. But it prevents new contributors for misusing it.

I touched a lot of other files to use config.Config.instance() instead of Config(). I also improved the unittests because most of them did create their own Config instance (most of them via generic.TestCaseCfg base class). Now all unittest do destroy there instance if they have created that instance them selfs.

PS: You have to squash before merge Sorry for the 13 commits. This PR was intended to have only one commit but I misused git.

buhtz avatar Sep 22 '22 22:09 buhtz