I was reading what a service locator pattern is from this article, and now I'm just wondering if I merge service and locator classes is it still a service locator pattern or not? And if not, do you think this implementation is usable enough as single or service locator pattern? (since the example was an audio manager I'll give same example here)
class IAudio{
private:
static IAudio* instance;
static IAudio _NULLINSTANCE;
public:
IAudio()
{
instance = &NULLINSTANCE;
}
IAudio* getInstance()
{
return instance;
};
void registerInstance(IAudio* pInstance)
{
instance = pInstance;
}
virtual void load(const char* path)
{
//do nothing
}
virtual void play(const char* path)
{
//do nothing
}
virtual void stop(const char* path)
{
//do nothing
}
};
And then I'll inherit classes I need from AudioManager and call registerInstance in my initialization function.
char*? At leastconstit, if not evenconst std::string&. – The Communist Duck Jun 6 '11 at 17:40