实体、值对象或者它是什么以及它应该在哪里?

发布于 2024-08-21 08:58:28 字数 589 浏览 5 评论 0原文

我有一个名为“工具”的课程。工具具有以下属性:名称、描述和一些特定的其他属性。工具很特别,因为名称和其他都是只读的,但描述可以由用户修改。

工具的数量是恒定的并且在开发时是已知的。它不是值对象,因为我需要查询它们并向用户显示可以在哪里更新描述。因此,它是一种实体,但用户无法创建新工具。

我正在寻找采用这样的工具的可能性:

Tool.SomeGreatTool

其中 SomeGreatTool 是名称为“Some Great Tool”的工具,并且描述应该与用户指定的相同。

吉米·博加德有解决方案几乎完美,但 NHibernate 知道有关 SomeGreatTool 的任何信息,并且 Description 将为空。

如何修改吉米的解决方案或如何以不同的方式做到这一点?如何从数据库实例化SomeGreatTool?

I have class called 'Tool'. Tool has properties like: Name, Description and some specific others. Tool is special because Name and others are read only but description can be modified by users.

Count of tools is constant and known at development time. It is not Value Object because I need to query them and show to users where they can update Description. So, it's kind of Entity but users can not create new Tools.

I'm looking for possibility to take Tool like this:

Tool.SomeGreatTool

where SomeGreatTool is Tool with name "Some great tool" and description should be the same like this specified by user.

Jimmy Bogard has solution almost perfect but NHibernate know anything about SomeGreatTool and Description will be null.

How to modify Jimmy's solution or how to do it different way? How to instantiate SomeGreatTool from database?

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

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

发布评论

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

评论(1

咿呀咿呀哟 2024-08-28 08:58:28

我们仍然将这类半常数数据视为一种众所周知的实体。我们为工具类型创建值对象/枚举类,但将工具类型与工具分开。您仍然需要转到持久存储来执行类似 ToolRepository.Find(ToolType.Screwdriver) 的操作。即使每种工具类型只有一个工具,您仍然需要区分这两个概念。

We still treat these kinds of semi-constant data as a sort of well-known entities. We create value objects/enumeration classes for the tool types, but separate tool types from tools. You still need to go to the persistent store to do something like ToolRepository.Find(ToolType.Screwdriver). Even though there will be only one tool per tool type, you'd still separate these two concepts.

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