Hi ,
I have 3 interface classes IVideo , IAudio , IGPIO
and three other classes that will implement those interface: Video_impl , Audio_impl , GPIO_impl
.
Things is simple so far.
But then ,I want all those object to be singleton. Here are the questions:
Is it a good idea to abstract an Interface ISingleton
, so that Video_impl , Audio_impl , GPIO_impl
(or IVideo , IAudio , IGPIO
?) can inherit from it?
I was thinking of implement it in following way. Is it recommended? I think there must be better ways.
//Isingleton.hpp
template <class T>
class ISingleton
{
public:
virtual T *getInstance() = 0;
};
class IGPIO
{
public:
virtual int SelectAudioInput() = 0;
};
class GPIO_impl : public IGPIO, public ISingleton<IGPIO>
{
public:
IGPIO *getInstance();
int SelectAudioInput() ;
private:
IGPIO *instance;
};