模拟以下场景的最佳方法
我开始进入 DD 世界,并尝试构建一个足够简单的应用程序。我有几个关于如何选择对我的域进行建模的问题。
我的应用程序允许用户订购贺卡。 用户可以在一份订单中订购任意数量的卡。 当选择要订购的卡片时,他们会浏览卡片目录。然而,卡片目录并不存储在本地,而是从外部系统检索,但是他们在当前会话中浏览到的每张卡片都将在该会话的生命周期内本地缓存在数据库中,以防他们希望添加到订单中。
当他们将卡添加到订单时,它会出现在新的订单行项目中。然后他们必须指定订单行项目、颜色、问候语等的一些其他详细信息...
我的问题是这样的: 如何在我的域中对卡进行建模。我将订单作为聚合根,其中包含许多订单行项目。每个订单行项目都有一定的属性和一张卡片。
但是,我的卡片目录还将有一个卡片概念,该概念与我的订单行项目上的卡片具有相同的属性。
我将这些卡片建模为 2 个独立的实体(CatalogueCard 和 OrderCard)是否正确,即使它们具有相同的属性集?
对于卡必须发送到的地址(每个订单行项目都有一个地址)和订单的帐单地址,也可能会提出同样的问题。这些应该被建模为完全独立的实体吗?
提前致谢
I am starting of in the world of DD and am attempting to build a simple enough application. I have a few questions on how I am choosing to model my domain.
My application allows users to order greeting cards.
The user can order any number of cards in one order.
When choosing a card to order they browse the card catalogue. THe card catalogue however is not stored locally, its retrieved from an external system, however every card they have browsed to in their current session will be cached locally in the database for the lifetime of that session in case they wish to add to the order.
When they add a card to the order, it goes on a new order line item. THey then must specify some other details for the order line item, colour, greeting etc...
My question is this:
How do I model the card in my domain. I have Order as an aggregate root, with many order line items. Each order line item will have certain attributes, and a card.
However my card catalogue will also have a card concept which will have the same properties as the card on my order line item.
Am I correct in modelling these cards as 2 seperate entities (CatalogueCard and OrderCard) even though they have the same set of properties?
The same question could be posed also for the address a card must be addressed to(each order line item will have an address) and the billing address for the order. Should these be modelled as completley seperate entities?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,您在对域进行建模时看到业务实体概念重复出现,这意味着您可能走在正确的轨道上。但是,如果您有两个具有相同属性集的对象,那么您绝对应该只使用一个。 CatalogueCard 和 OrderCard 应该是实例名称,而不是类名称,除非您希望进行一些更改,那么您可以从 Card 基类继承。您的地址类别也是如此。只需使用一种地址类别。地址类型应该只是另一个属性,它可以是模型支持的地址类型的枚举值。
The fact that you're seeing business entity concepts repeated as you model your domain means that you're probably on the right track. But if you have two objects with the same set of attributes you should definitely just use one. CatalogueCard and OrderCard should be instance names, not class names, except if you expect some change then you can inherit from a base Card class. Same goes for your address class. Just use one address class. The address type should just be another attribute which could be an enum value of the types of addresses your model supports.