Derived Classes – Understanding Derived Classes and Namespaces

inheritancenamespace

I am deriving a class, for use in my application, from a class provided by another group. Should the derived class be in the namespace for my application or the namespace of the parent class?

While I am extending the class to add features I need, the added features are not specific to my application. The project that contains the parent class is also rarely updated so there is a chance my additions would never be picked up… Maybe none of this matters.

Best Answer

It should be in the namespace of your application

Since you are extending the class to add features for your application, the class should be part of your application's namespace, not a different one.

Now if other applications would also be using this derived class in addition to your 1st one, then I would make a separate library file (and namespace) which contains any customized components from the first namespace, and import this library into any application that needs to use the derived class.