Let say we need to have just one instance of some class in our project. There are couple ways of doing it.
I want to compare. Please can you review my understanding.
1) Classical Singleton pattern
2) Completely static class (all methods and members are static).
As I understand the differences are following:
a) The order of initialization of static members across different units isn't defined. So, completely static members initialization can't use any static members/functions from other modules. And singleton doesn't have this problem.
b) We have to deal with threading for getInstance() of Singleton. However, completely static class doesn't have this problem.
c) Access to methods looks a little bit different. Foo::bar(); vs Foo::getInstance()->bar(); Generally, singleton can return NULL to identify that there were some problems with construction of object and static class can't.
d) Definition of class looks a little bit clunky with bunch of statics for static class.
Have I missed anything?