for example, we have two classes for parsing the resumes, one to parse Excel and the other to parse HTML.what my colleagues love to do is to name these two classes the same name and put them into different namespace,like shown as below:
namespace XX.ResumeParsers.Excel
class ResumeParser{}
namespace XX.ResumeParsers.Html
class ResumeParser{}
I feel it is not a good idea, I'll prefer to rename the classes, and put them into one namespace(but in different files if needed):
//in Excel folder under ResumeParsers folder
namespace XX.ResumeParsers
class ExcelResumeParser{}
//in Html folder under ResumeParsers folder
namespace XX.ResumeParsers
class HtmlResumeParser{}
thus, the Hierarchy still exists in the folder, but the namespace is the same(do not match the folder hierarchy exactly), is that OK?
and if I am right, any idea how to persuade my colleagues? or is there any significant drawback in their solution?
thanks.
namespace definitionMultiple namespace blocks with the same name are allowed. All declarations within those blocks are declared in the named scope.
Inside a namespace, no two classes can have the same name.
Every part of the partial class definition should be in the same assembly and namespace, but you can use a different source file name.
Names are what can be traditionally thought of as "variables". Namespaces are the places where names live. Typically this is a module. Each module (file) has it's own namespace -- Or it's own set of names which map to a corresponding value ( a->1, b -> 2 in my example above).
It's not usually a good idea, no - particularly if you need to use both classes from the same code. Whether they should be in different namespaces or not is a separate decision, but I'd definitely call them HtmlResumeParser
and ExcelResumeParser
instead of trying to make the namespace communicate context. It will make it much easier to determine exactly what you're talking about when reading code.
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