域实体属性名称

发布于 2024-07-12 13:02:45 字数 129 浏览 4 评论 0原文

对于域实体,属性名称是否应该以实体名称开头? IE 我的类 Warehouse 有一个属性 WarehouseNumber。 该属性应该命名为 WarehouseNumber 还是简单地命名为 Number?

想法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

若无相欠,怎会相见 2024-07-19 13:02:45

我更喜欢不使用前缀,我发现它更容易输入,也更易读,实体的上下文几乎总是显而易见的。

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.

夜司空 2024-07-19 13:02:45

想想你所代表的概念、它们出现的背景以及它们的相对频率。

在本例中,数据是 WarehouseNumber。 在 Warehouse 的上下文中,Number 是正确限定的。 在 Warehouse 之外,WarehouseNumber 将被正确限定,即 Order.WarehouseNumber

那么,Warehouse.WarehouseNumber 就显得多余了。

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.

过去的过去 2024-07-19 13:02:45

我永远不会在代码中为它们添加前缀。 您应该始终使用有意义的变量、属性和方法名称,从而使前缀变得多余。

var currentWarehouse = warehouseService.Find(id);

var number = currentWarehouse.Number;

或者

var number = order.Warehouse.Number;

当涉及到将它们存储在数据库中时,我对这个问题不太决定。 有句话要说:

select   *
from     dbo.Warehouse
where    WarehouseId in (
             select   WarehouseId
             from     ...
         )

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     ...
         )
阪姬 2024-07-19 13:02:45

这是对象关系阻抗不匹配的模式之一。 在面向对象中,实体名称的前缀似乎不合适。 然而,在 RDMBS 中,实体前缀唯一标识一个属性,建议避免这种情况:

SELECT
邮政编码——天啊!!! 我是哪张桌子来的! C.邮政编码或S.邮政编码??!???!


客户 C

INNER JOIN 供应商 S
ON C.PreferredSupplierID = S.SupplierID

我的建议是任意选择一个约定并大致坚持它。 毕竟这是一个节省时间的约定! 可能并不重要..:)

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.. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文