Name Conventions and Namespaces

If I have objects on one layer with the same name as objects on another level, is it better to change the names of objects with a certain prefix or have a new namespace and refer to them with full names? For instance:

namespace Project1.Data Object Person; namespace Project1.Model Object Person; 

 Data.Person.Name=Person.Name; OR dbPerson.Name= Person.Name; 
+4
source share
5 answers

I would use namespaces and namespace aliases, for example:

Define your classes in the appropriate namespaces:

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

And where you use classes, either use fully qualified names, or set an alias for 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; 
+12
source

It depends on how often you refer to the overloaded name.

If you use it several times in one file, use the first method.

If you use it only once or twice, write down the full name so that other people do not have to look for a hunt around at the top of your file to find out which object you are accessing.

+2
source

It really depends on the frequency that you request from each of them. As a rule, I use an abbreviated version for the type that I refer to most often, and use a longer name for the type that is less commonly used. In the end, I would say that if you have a lot of usages of both in the same file, you should use a namespace alias, but for me this is the last resort only after the code has swollen to such an extent, follow that going on.

+1
source

The very thought. I think choosing class names is a bad idea. For example, I have a data access layer and a business layer. Both deal with users. So, I have a...

Project1.Business.User Project1.DataAccess.User

trying to think of inventive new names for classes is a waste of time and will probably mean odd names for classes with little value. Naming classes can have enough headaches.

I agree with McWafflestix "I use the shortened version for the type that I mean most often and use the longer name for the type that is less commonly used."

+1
source

It's simple. Listening to the .NET Framework guides at a time actually helps (although a lot of the material in the book is just Java Style Elements again in Redmond Wonderland).

Similar type names should be avoided in the namespaces of cross or in-project / library moves, i.e. mixing between domains and models in general (even in C ++, which is extremely strict and powerful, it also has embodiment in compilers, permissions, and enum-style compiler errors).

Therefore, even a full qualification is not always perfect (and the btw and "use" aliases are extremely limited and at best lead to soft duplication, and also prove the weakness of C # in general programming, etc.).

In my experience, data domain types are the main goal for a more suitable name and therefore for refactoring names:

a) cheap (like a process in rich AST, but simple adt-s support like in C #, right-click in the IDE and feel strong depending on dynamic fans / supporters of the dynamic Ruby type)

[can also be read as: 4.0 dynamic sheep functions will blame everyone, but not think about namespaces or functional JS, C-patterns (not C-c-classes) or the like]

b) conveys semantics better, i.e. intention (i.e. plumbing + support to create your own processing)

c) usually of a primitive but typed nature or message (not OO typed, i.e. criticism in the OO style, as in the aforementioned book, which itself breaks directly from the intro, raises all the β€œModels” to the earth link)

d) and 'aliasing' becomes a useful artifact in cross-domain use (which is actually possible and quite suitable by 2020, for example ... programming of type values)

There are actually no rules, but be careful that you see confusion of namespaces during development when they are least expected. This means only one thing for guided thinking dev: confusion. Plus a few less serious, more compilation and IntelliNonsense errors, of course ..

A tough problem in all languages, so this is your design / naming problem. Even tool suppliers can spoil parsing machines ... say, outputting extended popular IDEs based on outdated browsing information; then again, others do well with managed languages.

Not that I am against duplicating names, there are cases (they are tough, but necessary) when mixing two + interop + representations, etc. other models where the same name makes it more readable; i.e. where duplication is a necessity of double use .. but these are lower level idioms that C # are not friendly or discouraging (re: in favor of overhead).

+1
source

All Articles