views:

237

answers:

4

I sort of have naming problems of my classes/namespaces/controls.

In my business library I have namespace called Shopping. It contains the following classes: ShoppingCartItem
ShoppingCart
ShoppingCartManager

In my ASP.net application I want to create a control that graphically represents the items of a ShoppingCart instance. Normally I would call that control ShoppingCart, but yet another class called ShoppingCart? Of course compilation et cetera would work, but I think its still ugly. I think I have a problem that I name my business classes excatly what they are supposed to represent. Because when it comes to the presentation layer it would name the controls that are supposed to represent the business class the same.

I think I could add a suffix like "View", but I want to do it right.

What is the recommend naming conventing for a multi tier application?
How should I name the control that represents the items of a ShoppingCart in the presentation layer?

Edit: Related Questions: http://stackoverflow.com/questions/3742112/how-should-i-name-database-wrapper-object

+8  A: 

Other StackOverflow folks may know better, but as far as I know, there's no commonly-accepted or industry-standard naming convention relating to tiered architecture. Though I think you're on the right track: moreso than the specific naming, choosing an approach and using it consistently will help make your code more maintainable.

mikemanne
A: 

You should decide on the naming conventions you are going to use before you begin your project. The .NET Framework contains a number of suggestions on naming conventions, you can find Visual Basic® naming convention suggestions at this location in the docs:

ms-help://MS.VSCC/MS.MSDNVS/vbcn7/html/vaconVBNamingRules.htm

It is important to decide on and adhere to a set of naming conventions than to limit yourself to a particular one. It is alsp important to think through the impact of the naming conventions you use. For instance, I still like to prefix control names with the type of control because I can type "txt" in the code editor, press Ctrl+Space, and get a list of all the textbox controls on a form.

Check out this link for a more detailed discussion.

Vinay B R
How am I supposed to use that **ms-help** docs location?..
Regent
open visual studio press F1 and copy the url there. If you have the complete MSDN installation u will see the page. if not go to MSDN.com and search for Visual Basic naming convention suggestions. Dont think the answer deserved a down vote just beacause you could not figure this out
Vinay B R
@Vinay B R, just checked that I have full MSDN library installed, but still no luck with opening that location. Was it difficult to give a [MSDN link](http://msdn.microsoft.com/en-us/library/0b283bse.aspx) in the first place? Anyway I was unable to find any multi-tier naming-related information after following those links.
Regent
@Regent: I found the link Vinay B R intened to show me directly. Click on his bold marked "Check out this link" and follow the first link. Or if you are too lazy, copy this link: http://msdn.microsoft.com/en-us/library/czefa0ke%28vs.71%29.aspx
citronas
@citronas, the link you mentioned is not related to the *ms-help* location mentioned. But that's not the point, the point is that in my opinion this answer doesn't answer the question nor do any links it contains.
Regent
These days, the strength of refactoring tools greatly reduces the need to "decide on the naming conventions before you begin your project." Often, the best naming convention only emerges once you're deep into the project. The ideas a team has before starting the project sometimes change drastically over time, especially in the face of ever-changing requirements. I agree, general guidelines are good but there's no need to have *every* duck in a row "before beginning" a project.
gmale
+10  A: 

In the MVC paradigm, it's fairly common to have Foo, FooView, and FooController.

You might decide it's easier to stick them in a different hierarchy (Shopping.Model.Cart, Shopping.View.Cart). It's conceptually clean, but I think it's rather unreadable. You can use distinct names in different namespaces instead (Shopping.View.CartView).

A good IDE will let you move/rename things, though, so it's not worth spending too much time worrying over picking the perfect name for something. It's more important to be very clear on what you're modeling and what its limitations are. For example...

  • Is Car an instance of a car or a particular make/model of car? Is a motorcycle a car? If you're going to rename it to Vehicle, is a bicycle a vehicle?
  • Is an Item a type of item, an instance of the item, or quantity instances of the item?
  • Is ShoppingCart just a list of items/quantities, or does it have other features? Does it merge duplicates of an item by summing the quantity?
  • Is a wishlist a special kind of shopping cart (one you haven't bought yet), or something else?
  • Can you "save" a shopping cart and get a quote (so you can print it out, take it to your boss, get it signed off, and then buy it)? Where is the quote stored?
tc.
+2  A: 

You can use namespace to separate your shopping cart UI and business entity, example:

  • YourApp.Web.UI.ShoppingCart (Your shopping cart web control)
  • YourApp.BusinessEntity.ShoppingCart (Your shopping cart class in your business logic layer)

When you create/use a shopping cart object, it might not be obvious at first look whether the object is a UI control or an entity class, but your IDE (visual studio) will provide you intellisense when you are writing code and a tooltip when you mouseover the name which can ease your problem.

Alternatively, if you really want to ease your eyes for reading, you can use prefix when naming your object:

  • YourApp.Web.UI.ShoppingCart uiShoppingCart;
  • YourApp.BusinessEntity.ShoppingCart beShoppingCart;
Gan