Trying to achieve a design where the classes that implement interfaces should only be callable from a Library. In other words, the access to the implemented interfaces should be through the library (TopLib). Seems like the case where delegate should be used. What do you think of the design ? This works, but would appreciate feedback and suggestions on making it better and robust and fool proof.
class Interface
{
protected:
virtual void hi(void) = 0;
};
class ABC : private Interface {
protected:
ABC() {}
virtual void hi() {
std::cout << "abc" << std::endl;
}
};
class XYZ : private Interface {
protected:
XYZ() {}
virtual void hi() {
std::cout << "xyz" << std::endl;
}
};
template<typename T>
class TopLib : private T
{
public:
void sayhi() {
hi();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
TopLib<ABC> b;
b.sayhi();
TopLib<XYZ> c;
c.sayhi();
//c.hi(); <- fails
//ABC test; <- fails
//test.hi(); <- fails
getchar();
return 0;
}