title: Struct vs namespace for C++ component based design
body: <p>We have a component based C++ design, where each component is comprised of a public outer class that is used to group component interfaces.  Each interface is defined as a nested class as shown below.</p>
  
  <pre><code>struct ComponentContainer {
  
      class InterfaceClass_1 : public ComponentInterface {
          public:
          virtual ~InterfaceClass_1 ()              = 0;
          virtual InterfaceClass_1* GetInterface()  = 0;
          virtual void InterfaceMethod1 ()          = 0;
          virtual void InterfaceMethod2 ()          = 0;
      };
  
      class InterfaceClass_2 : public ComponentInterface {
          public:
          virtual ~InterfaceClass_2 ()             = 0;
          virtual InterfaceClass_2* GetInterface() = 0;
          virtual void InterfaceMethod1 ()         = 0;
          virtual void InterfaceMethod2 ()         = 0;
      };
  };
  </code></pre>
  
  <p>My first question is whether or not it is correct / advised to use a class as the container for a component?  Is it more correct to replace "struct ComponentContainer" with "namespace ComponentContainer"?  </p>
  
  <p>Since Interface classes are always public, I have been thinking of changing the structure to look like this:</p>
  
  <pre><code>namespace ComponentContainer {
  
      struct InterfaceClass_1 : ComponentInterface {
          virtual ~InterfaceClass_1 ()              = 0;
          virtual InterfaceClass_1* GetInterface()  = 0;
          virtual void InterfaceMethod1 ()          = 0;
          virtual void InterfaceMethod2 ()          = 0;
      };
  
      struct InterfaceClass_2 : ComponentInterface {
          virtual ~InterfaceClass_2 ()             = 0;
          virtual InterfaceClass_2* GetInterface() = 0;
          virtual void InterfaceMethod1 ()         = 0;
          virtual void InterfaceMethod2 ()         = 0;
      };
  };
  </code></pre>
  
  <p>Is this method of defining a component preferable to my first example?  Are there any fundamental flaws that I need to look out for?</p>
  
  <p>Thanks.  </p>