1

So I am reading Clean Code and I want to write my class names with the proper amount of context, but how does .NET namespaces play into the concept of Meaningful Names?

Do I forego context in the class name that has been provided in the namespace?

For example, If I have the following namespaces

MySolution.Event.Registration.BeginRequest  
MySolution.Event.Registration.EndRequest  
MySolution.Event.Registration.Error

Should I name the classes EventRegistrationBeginRequest, etc.?

  • Related reading: .Net Framework Naming Guidelines. – Machado May 4 '17 at 21:07
  • 2
    Will the namespace context be visible in code that uses these classes? E.g. do you expect to always see MySolution.Event.Registration.BeginRequest, or would users import that class name and write BeginRequest? In my experience, it's usually the latter – thus indicating that each class name should provide enough context in isolation. – amon May 5 '17 at 7:17
1

Avoid classes with identical names, even if the name spaces differ.

The problem is, you import and forget about the namespaces and it becomes unclear which class is meant to be used.

Refactoring can be a nightmare of you move the class to a different project.

I would also not recommend the 'clean coding' BigLongClassNameOfDeath either. Try and keep your names specific to your functionality, avoid public Request, Response, Error etc, or at least move them to a common library

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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