Static class, Singleton, or global?
Posted on 2013-11-27
(I come from a C# background, which doesn't translate easily to C++ I've learned.)
State Design Pattern
I have a ClassOne, and in this class it holds another class which is the current state, say classes StandardStateA, StandardStateB.
I also have a ClassTwo, and a ClassThree, which also have a current state class.
There's no reason to have multiple copies of StandardStateA, StandardStateB. The big deal is to be able to easily switch between them.
But static classes don't exist in C++ I'm told. So what other options do I have?
Do I create a global variable instance of StandardStateA, StandardStateB, creating it outside of any class? Or do I go with Singleton? Perhaps I say "forget it" and just go with each class creates its own personal identical copy of StandardStateA and StandardStateB? Is this one of those situations where there is no right answer?