This situation probably is not entirely uncommon to some of you: you have some functionality to put in a class but the perfect name (*) for that class is taken by one of the classes in the System
namespace or other namespace/class that's not yours but you're using
/import
ing.
(*) By perfect I mean small, concise and clear names.
For instance I have an Utils
class that has a Diagnostics
(mostly debug utils) class and a Drawing
class. I could:
DrawingUtils
class and a DiagnosticsUtils
class, but that just smells like bad structure. I think options 1-3 aren't promising :(
Since my chosen answer doesn't address the problem definitively (neither I do), what I'd recommend for people facing the same situation is to ask yourselves: Will you frequently use the conflicting BCL class/namespace? If no, then let your name conflict (as I did with Diagnostics). If yes, add a word that limits the possibilities of your class/namespace.
In practice, this means:"Drawing"
: Something that draws."MyCustomControlDrawing"
: Something that draws only on MyCustomControl
. e.g.: "WidgetDrawing"
.
Another solution to take a look next time: Extension Methods (courtesy of Lawnmower).
I don't see any issue with keeping the names Drawing
, Diagnostics
etc. That's one of the purposes of namespaces, to resolve naming conflicts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With