title: design pattern such that access to the Derived class is only possible through a library
body: <p>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. </p>
  
  <pre><code>class Interface 
  {
  protected:
      virtual void hi(void) = 0;
  };
  
  class ABC : private Interface {
  protected:
      ABC() {}
      virtual void hi() {
          std::cout &lt;&lt; "abc" &lt;&lt; std::endl;
      }
  };
  
  class XYZ : private Interface {
  protected:
      XYZ() {}
      virtual void hi() {
          std::cout &lt;&lt; "xyz" &lt;&lt; std::endl;
      }
  };
  
  template&lt;typename T&gt;
  class TopLib : private T
  {
  public:
      void sayhi() {
          hi();
      }
  };
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      TopLib&lt;ABC&gt; b;
      b.sayhi();
  
      TopLib&lt;XYZ&gt; c;
      c.sayhi();
      //c.hi(); &lt;- fails
  
      //ABC test; &lt;- fails
      //test.hi(); &lt;- fails
  
      getchar();
      return 0;
  }
  </code></pre>