views:

152

answers:

3

Hello,

I was wondering is constantly reusing namespace names is valid for c# conventions/best practises.

I am develop most of my programs in Java, and i would have a packet for implementations, eg:

com.ajravindiran.jolt.game.items.sql
com.ajravindiran.jolt.game.users.sql
com.ajravindiran.jolt.events.impl
com.ajravindiran.jolt.tasks.impl

Let's talk about com.ajravindiran.jolt.game.items.sql, which is most close my situation. I current wrote a library that wraps the MySQL Connection/Net into a OODBMS.

So i have an interface called ISqlDataObject which has the following members:

bool Insert(SqlDatabaseClient client);
bool Delete(SqlDatabaseClient client);
bool Update(SqlDatabaseClient client);
bool Load(SqlDatabaseClient client);

and used like such:

public class SqlItem : Item, ISqlDataObject
{
    public bool Load(SqlDatabaseClient client)
    {
        client.AddParameter("id", this.Id);
        DataRow row = client.ReadDataRow("SELECT * FROM character_items WHERE item_uid = @id;");
        this.Examine = (string)row["examine_quote"];
        ...
    }

    ...
}

called:

SqlItem item = new SqlItem(int itemid);
GameEngine.Database.Load(item);

Console.WriteLine(item.Examine);

So i was wondering if it's ok to add the sql editions of the items into something like JoltEnvironment.Game.Items.Sql or should i just keep it at JoltEnvironment.Game.Items?

Thanks in adnvanced, AJ Ravindiran.

+2  A: 

For naming conventions and rules, see MSDN's Framework Guidelines on Names of Namespaces.

That being said, that won't cover this specific issue:

So i was wondering if it's ok to add the sql editions of the items into something like JoltEnvironment.Game.Items.Sql or should i just keep it at JoltEnvironment.Game.Items?

It is okay to do either, and the most appropriate one depends a bit on your specific needs.

If the game items will be used pervasively throughout the game, but the data access will only be used by a small portion, I would probably split it out into its own namespace (though probably not called Sql - I'd probably use Data or DataAccess, since you may eventually want to add non-SQL related information there, too).

If, however, you'll always use these classes along with the classes in the Items namespace, I'd probably leave them in a single namespace.

Reed Copsey
+1  A: 

You're asking about naming conventions, and the answer is, it's really up to you.

I allow for extra levels of hierarchy in a namespace if there will be multiple implementations. In your case, the .Sql is appropriate if there is some other storage mechanism that doesn't use Sql for queries. Maybe it's XML/Xpath. But if you don't have that, then it seems like the .Sql layer of naming isn't necessary.

At that poiint, though, I'm wondering why you would use {games,users} at the prior level. Feels like the namespace is more naturally

JoltEnvironment.Game.Storage

..And the Fully-qualified type names would be

JoltEnvironment.Game.Storage.SqlItem JoltEnvironment.Game.Storage.SqlUser

and so on.

If a namespace, like JoltEnvironment.Game.Items, has only one or two classes, it seems like it ought to be collapsed into a higher level namespace.

Cheeso
+1  A: 

What are you calling SQL Editions? Versions of SQL Server? Or Version of Database Connections? If the later, I would do something like:

JoltEnvironment.Game.Items.DataAccess.SQLServer
JoltEnvironment.Game.Items.DataAccess.MySQL 
JoltEnvironment.Game.Items.DataAccess.Oracle

etc...

If the former, I thought that ADO.NET would take care of that for you anyway, based on the provider, so everything under the same namespace would be ok.

Wagner Silveira