I have two different namespaces, with lots of classes with the same name. I believe some code will make it easier to understand:
namespace Print.Pdl.PostScri
My opinion is you should use a naming scheme reflecting specialization.
I mean you don't need to think about if it's a prefix, suffix or any other. Just write names that may clearly identify classes.
Honestly I believe namespacing wouldn't repleace a right class naming scheme, because namespaces are an organizational thing while classes are part of what your program does.
So, at the end of the day, I'd choice your second option: specialized naming for namespaces and classes.
Different namespaces are just that... Different, name, spaces so you shouldn't worry at all (generally) about duplicate names across namespace boundaries.
However, you should be conscious of usage. e.g. you are creating a layered app with many different layers (in different namespaces), you would not want to duplicate class names that might be shared across layers.
If you feel it is sensible to use duplicate naming between namespaces, you can always use the handy using statements for renaming in consuming classes e.g.
you have two User classes :
Data.Entities.User;
App.Core.User;
And want to use them in the same place...
You can use a simple using statement such as
using HttpUser = App.Core.User;
To alias one of them and so avoiding full qualification, and avoiding any confusion.
Developers maintaining the code after you will appreciate it if you try and avoid duplicating class names. It just makes it hard to tell at a glance what class is being used.
Nolde,
I don't think you should sacrifice the architecture in favor of readability. I believe its more intuitive if you keep the same class names as this makes it simpler if you are switching from PCL to PostScript and vice-versa.
If you have to use both classes in the same code file, create an alias for the namespace. It will be very clear to read:
using Pcl = Print.Pdl.Pcl6.Operators;
using PostScript = Print.Pdl.PostScript.Operators;
...
// use PCL
Pcl.BaseOperator.DoSomething();
// Use PostScript
PostScript.BaseOperator.DoSomething();
Thanks, Luciano Bargmann
If there's no functional or interface difference between the two proposed base classes then maybe create another, general namespace with the BaseOperator in it - and just define it once.
It's a tricky question IMO. To answer it well, you need to know how often people are likely to use both namespaces at once, and how annoyed they get at having to prefix everything with a namespace.
I personally tend to lean towards the "different names". I think of the namespaces as a mechanism to limit the set of names visible in the code, and a safeguard against the unlikely event that names clash even within this reduced set. So keeping the clash "unlikely" is important. Therefore, I personally wouldn't design with a clash on purpose.
Especially since in your case the difference is so small: BaseOperator
is only a tad shorter than BasePsOperator
.