Sign in to follow this  
storage

[.net] Class and namespace naming

Recommended Posts

I'm trying to decide what to name my classes and namespaces, and it's working well at the moment. The thing I'm wondering about is what to name my "graphics device" class and its interface. At the moment it looks like this:
Engine.Graphics.IDevice
Engine.Graphics.GLDevice
Engine.Graphics.D3DDevice
But I'm going to add a "sound device" class at a later stage, and I would like it to be called *Device as well. Like this:
Engine.Sound.IDevice
Engine.Sound.FMODDevice
And so on. Will there be a problem with having two classed named the same? Should I name the classes IGraphicsDevice/ISoundDevice instead? If so, should I keep the Engine.Graphics/Engine.Sound namespaces? Thanks a lot in advance!

Share this post


Link to post
Share on other sites
You can have classes named the same in differnt namespaces. Just remember that when you add those namespaces to your project that if you use "using" then you will come into a naming collision. If you are using both in the same file you will need to make sure you use thier complete names including the namespace so the complier can tell which one you want.

I would suggest to the begining of your namespace you add your "name" to it. There are countless number of "Engine" namespaces, this will keep your as unique. Just a suggestion.

theTroll

Share this post


Link to post
Share on other sites
The recommended namespace convention to avoid clashes from Microsoft is:

<company>.(<product>|<technology<)[.<Feature>][.<subnamespace>]
(from Framework design guidelines book)
See also http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconnamespacenamingguidelines.asp

This helps avoid clashes and makes things consistent which is good if you ever intend others to use your API.

If you never intend for anyone else to use it then do whatever feels good.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this