5

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.

7

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.

  • "the added features are not specific to my application" Regardless, I agree. – Matt Mar 15 '12 at 19:52
  • Based on popular opinion you have won. Hooray! – Charlie Mar 16 '12 at 14:11
2

You are sub classing an object from the library (your parent class namespace) to make the library evolved rather than to create hybrid between the application space and the library. Hence, ideally such derivation should/could be helpful to other applications as well. If the derived class is in same namespace as parent class, this would be relatively straight forwards; where as if it is in your app's namespace, would introduce an unnecessary dependency for the App2 on your app. Hence, the derived class should be in libraries namespace.

Further you may want to read this: Why is subclassing too much bad (and hence why should we use prototypes to do away with it)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.