tags:

views:

308

answers:

4

For domain entities, should property names be prefaced with the entity name? I.E. my class Warehouse has a property WarehouseNumber. Should that property be named WarehouseNumber or simply Number?

Thoughts?

+3  A: 

I prefer not using the prefix, I find it easier to type, and more readable, the context of what the entity is almost always apparent.

FlySwat
+2  A: 

Think of the concepts you are representing, the context in which they appear, and their relative frequency.

In this case, the pieces of data are Warehouse and Number. In the context of a Warehouse, Number is properly qualified. Outside of a Warehouse, WarehouseNumber would be properly qualified, i.e. Order.WarehouseNumber.

Warehouse.WarehouseNumber, then, would be redundant.

Bryan Watts
+1  A: 

I would never prefix them in code. You should always have meaningful variable, property and method names making the prefix redundant.

var currentWarehouse = warehouseService.Find(id);

var number = currentWarehouse.Number;

or

var number = order.Warehouse.Number;

I'm less decided on the matter when it comes to storing them in the database. There's something to be said for:

select   *
from     dbo.Warehouse
where    WarehouseId in (
             select   WarehouseId
             from     ...
         )
Garry Shutler
A: 

This is one of those object-relational impedance mis match mofos. In OO, for sure the prefix of entity name seems not to fit. However, in an RDMBS the entity prefix uniquely identifies an attribute and is encouraged to avoid this:

SELECT PostCode --OMG!!! Which table do I come from! C.PostCode or S.PostCode??!??!

FROM Customer C

INNER JOIN Supplier S ON C.PrefferredSupplierID = S.SupplierID

My advice is to pick a convention arbitrarily and roughly stick with it. Its a convention to save time after all! Probably doesn't matter.. :)

Jimmy McNulty