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.
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;
};
};
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"?
Since Interface classes are always public, I have been thinking of changing the structure to look like this:
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;
};
};
Is this method of defining a component preferable to my first example? Are there any fundamental flaws that I need to look out for?
Thanks.