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.?

asked May 4, 2017 at 20:46
2
  • Related reading: .Net Framework Naming Guidelines. Commented May 4, 2017 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. Commented May 5, 2017 at 7:17

1 Answer 1

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

answered May 6, 2017 at 8:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.