I have a singleton, and I’m debating whether it would be bad practice to have some static methods that sort of hide the singleton’s usage from the client. For example:
Singleton::Instance()->Foo();
Vs.
Singleton::FooHelper();
Where FooHelper is defined:
class Singleton
{
...
static void FooHelper()
{
Singleton::Instance()->Foo();
}
...
}
Is the second solution considered bad practice? I wouldn’t be making helper functions for all the methods of Singleton, just the ones that are used very frequently by the client code.
This is not bad practice as long as 1° the original
Foo()method is still publicly available and 2° the naming scheme makes it obvious thatFooHelper()is equivalent to callingFoo()on the instance.Of course, if you find yourself always calling
FooHelper()and never callingFoo(), reconsider your design: the point of a singleton (as opposed to a plain global-functions-in-namespace approach) is that it’s an object — so at least some parts of your code should be using it as such.