Is it perfectly acceptable, from a "conventions" or "best practices" point
of view to have a class in one namespace extend a class in another
namespace?
I just came across this state of affairs in the .NET Framework itself and,
at first, it seemed somehow like a "bad thing" (in part because namespaces
are intended to group classes that serve some common purpose) - but after
about two seconds of thinking about it, I'm thinking that there is
absolutely nothing wrong with doing this - and in many situations, like in
large frameworks, it would even be unavoidable.
And example from the .NET Frameowork is:
System.ComponentModel.ComponentResourceManager
which extends
System.Resources.ResourceManager
Thoughts? Opinions? - specifically regarding the idea that it is (or is not)
perfectly acceptable to have a base class in one namespace, and then extend
that class in an entirely different namespace?
FWIW, I do understand that the classes, themselves, don't care about the
namespace in which they exist - at least not beyond qualifying references to
specific external classes.
Thanks.
Brendan G - 13 Mar 2008 05:47 GMT
This is just basic OOP principles, isn't it?
> Is it perfectly acceptable, from a "conventions" or "best practices" point
> of view to have a class in one namespace extend a class in another
[quoted text clipped - 21 lines]
>
> Thanks.
Roger Frost - 13 Mar 2008 05:54 GMT
> Is it perfectly acceptable, from a "conventions" or "best practices" point
> of view to have a class in one namespace extend a class in another
[quoted text clipped - 21 lines]
>
> Thanks.
If the extended class adds functionality specific to its namespace, why not
put it there?

Signature
Roger Frost
"Logic Is Syntax Independent"
Peter Duniho - 13 Mar 2008 07:09 GMT
> Is it perfectly acceptable, from a "conventions" or "best practices"
> point
> of view to have a class in one namespace extend a class in another
> namespace?
I think it depends on your definition of "extend". But for common
definitions, such as "inherit" or (now with C# 3.0) writing an extension
method for the class, I'd say that not only is it acceptable, it's the
most common way of doing it.
Every .NET Forms application has at least one custom Form-derived class,
and that class is never in System.Windows.Forms.
Similar situations may well exist within a development team. I don't see
anything fundamentally wrong with this kind of extension crossing
namespace boundaries.
Pete