Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer
    
"the added features are not specific to my application" Regardless, I agree. –  Matt Mar 15 '12 at 19:52
    
@Matt Ooops I misread that, thanks :) –  Rachel Mar 15 '12 at 19:54
    
Based on popular opinion you have won. Hooray! –  Charlie Mar 16 '12 at 14:11
    
and thanks for the input! –  Charlie Mar 16 '12 at 14:12

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)?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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