troubleshooting Question

Static class, Singleton, or global?

Avatar of deleyd
deleydFlag for United States of America asked on
10 Comments1 Solution357 ViewsLast Modified:
(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?

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros