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 I 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: How should I name database wrapper object?
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...
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?Item
a type of item, an instance of the item, or quantity
instances of the item?ShoppingCart
just a list of items/quantities, or does it have other features? Does it merge duplicates of an item by summing the quantity?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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With