2

I have a small issue with namespace and class naming. Here is a practical example:

ResourceLayer.cs - Public component that holds the manager and the map provider, implements an interface 
ResourceMapProvider.cs - Provides a bitmap representation of the resources
ResourceManager.cs - Is a repository of resources with some utility methods
Resource.cs - A resource entity

But I'm going to have a larger number of layers, each specialized so this is going to be replicated a lot.

I have no idea how to namespace it in a conceptually correct fashion. Here are my ideas and why I believe they don't work:

App.ResourceLayer - Same name as class, bad practice and had some scope issues
App.ResourceUtils - Good name, but ResourceLayer.cs doesn't really fit into the namespaces and I wouldn't know where to put it 
App.Resource - Same name as a class that would be in it, scoping issues (App.Resource.Resource) 
App.Resources - Confusing (App.Resources.Resource) , doesn't really fit the layer part (App.Resources.ResourceLayer) 

So, does anyone have any naming ideas?

asked Oct 4, 2016 at 6:57
6
  • Hmm , what do you mean? Commented Oct 4, 2016 at 7:02
  • Maybe they're just examples but your class names are very vague. What would ResourceManager.cs do? And why do you have a class named ResourceLayer.cs? Wouldn't a layer constitute multiple classes? Maybe you can give us more info on the responsibilities of these classes because it's hard to help with namespacing without understanding what the classes do. Commented Oct 4, 2016 at 7:10
  • I've added some basic descriptions. Ah, the "Layer" name is a concept of the application, I'm basically overlapping many data layers such as this in a visual way. It's not an architectural layer. Commented Oct 4, 2016 at 7:18
  • If my understanding of your naming-and-layers-pattern is correct you are going to have another set of classes named for example ImageLayer.cs, ImageMapProvider,...? So your namespacing-ideas would go with App.lmageLayer or App.ImageUtils,..? Commented Oct 4, 2016 at 7:43
  • Yeah, there's going to be , for example, an "ElevationLayer" which will have those components as well (maybe more, maybe others , etc) Commented Oct 4, 2016 at 7:48

2 Answers 2

1

Rename Resource.cs to ResourceEntity.cs and you can let it's namespace be Resource. Same with Elevation and all the others.

That solves the naming problem. Be sure you're comfortable with this cookie cutter design. It's easy to obsess on creating a predictable structure to work within and ignore problems caused because you insist on sticking with it rather than rethink the structure.

answered Oct 4, 2016 at 8:06
1

According to the C# naming guidelines, namespaces should be plural, eg. ResourceLayers rater than ResourceLayer. This avoids collisions between class and namespace name.

That said, you might not even need a separate namespace for each layer since in the naming scheme you suggest, the name of the layer is used in the names of all the components of the layer. So you don't really need a namespace to disambiguate. Having too many unnecessary namespaces leads to clutter.

answered Oct 4, 2016 at 8:24
2
  • Can you reference those guidelines somewhere? Commented Oct 4, 2016 at 11:52
  • @AdamPlocher: I have added a link. Commented Oct 4, 2016 at 12:06

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.