Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming Conventions and Namespaces

If I have objects on one layer with the same name as objects on another layer, is it best to change the object names with some prefix or have new namespace and refer to them with fully qualified names? For example:

namespace Project1.Data
Object Person;

namespace Project1.Model
Object Person;

Data.Person.Name=Person.Name;

OR

dbPerson.Name= Person.Name;
like image 444
zsharp Avatar asked Dec 04 '22 15:12

zsharp


1 Answers

I'd use namespaces and namespace aliases, e.g:

Define your classes in appropriate namespaces:

namespace Project1.Data
{
    public class Person {...}
}
namespace Project1.Model
{
    public class Person {...}
}

And where you use the classes, either use fully qualified names or define an alias for the namespaces (especially usefule if the full namespace is long):

using data = Project1.Data;
using model = Project1.Model;

data.Person p1 = new data.Person();
model.Person p2 = new model.Person();
//...
p1.Name = p2.Name;
like image 149
M4N Avatar answered Dec 20 '22 03:12

M4N