oop - 使用 DDD 建模时间表

标签 oop design-patterns domain-driven-design

我正在尝试为我的公司建模一个日程安排应用程序,可以使用一些建议。如果合适,我想遵循域驱动设计。

该域由一个 Show 对象组成,它代表一个贸易展览、展览或 session ,我们可能会在其中推广我们的产品。它具有开始和结束日期和时间、议程、演讲者名单、地点等。可以通过 Show 完成很多工作,例如分配演讲者、注册与会者、取消等。

我们通常作为一个或多个营销事件的一部分参加展会。事件也有开始和结束日期和其他信息,以及我们将为该事件参加的节目列表。我们可能会在一个给定的展会上推广多个事件。

节目可以从事件中添加或删除,当节目被取消时,它必须从与其关联的任何事件中删除。

我的第一个想法是拥有一个 Schedule 聚合根,其中包含一个 Campaign 实体列表,其中包含一个 Show 对象列表。但我需要一种访问独立节目的方法 - 一个节目可以与多个事件相关联。

看看我的用例,我正在开发一个 Silverlight 客户端(但也可能会移动)。主视图将是一个日历类型的 UI(如 Outlook),将每个 Show 显示为约会。还有侧边栏显示即将到来的节目、当前事件和具有后续任务的节目。当我双击任何这些 View 中的项目时,显示详细信息会显示在子窗口中。

关于如何在我的应用程序代码中对这个域建模有什么建议吗?

最佳答案

But I need a way to access stand-alone Shows - and a Show can be associated with more than one Campaign.

与其尝试将所有内容都放在 Schedule 聚合根(当您随意谈论域时,该术语不会出现在您的语言中),不如尝试使用 2 个聚合根 - Show 和 Campaign。

A Campaign also has start and end dates and other information as well as a list of Shows we will be attending for that Campaign.

Campaign 可能没有必要保留对 Show 的引用。如果节目知道它推广的事件,那么在您要显示事件信息时就足以找到它。

Shows can be added or removed from Campaigns and when a Show is cancelled, it must be removed from any Campaigns it was associated with.

No, it should not .
节目应该被标记为已取消,如果有必要,事件会隐藏它。

我会从类似 this 的内容开始.


It was only due to my attempt to be concise that Schedule was not introduced until I started discussing the model. In fact, the Schedule is the whole point of the app. The Schedule represents all of the Shows.

很可能有要求在您的领域模型中引入时间表的要求。但是因为我还没有听到它(或者对你的领域不够了解),我只会将我的应用程序命名为 Scheduler。或者 Scheduler bounded context,如果应用程序不仅仅是关于安排节目和事件的话。

Also, in the customers' minds the Show doesn't necessarily know about the Campaigns. In all of our discussions, they only ever referred to assigning Shows to Campaigns.

如果 Show 必须存在于“独立版本”中,则它是一个聚合根(将其下推到 Schedule 下不会改变任何事情,这只会增加一个抽象层。Show 仍将独立于 Campaigns)。如果需要弄清楚在“独立版本”中被视为关联的 Campaign/s Show,应该有关联 Show->Campaigns。尽管它可能感觉与域有点矛盾,但您可以将其视为一种牺牲。

我们用清晰的原始想法来交换表达自己的能力(Uncertainty principle 在这里可以用作一个很好的类比)。毕竟 - 我们无法完全彻底地捕获心智模型。

Logically I agree with your point but I would also want to ensure that there was only ever one instance of the Campaign shared by all Shows that has been assigned to it.

您应该稍微关注领域对象的生命周期。

对象的构造和重建之间存在巨大差异。通常,Campaign 只会构建一次,之后 - 它只会从数据存储中重建。如果您确保同一事件的不同实例(从域的角度来看)不能保存两次 - 通常这就足够了。

This is what led me to my original thought that Campaign was the root but doing so ignores the reality that there will be Shows that are not part of a Campaign.

是的......你是对的。

关于oop - 使用 DDD 建模时间表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8300849/

相关文章:

.net - 如何获得事件的反馈?

algorithm - 如何将 CLI 客户端实现到 golang 守护进程?

domain-driven-design - 实现 Udi 的抓取策略——如何搜索?

c# - 领域驱动设计应用服务

reference - DDD : Reference another aggregates child entity

r - 是否有可能使用Mixins在Raku中复制R的 'named vectors'概念的简便方法?

php - 冒号是什么意思(:) operator after member function name in php

c++ - 传递结构句柄(将 C 转换为 C++ OOP)

database - Data Mapper 可以调用另一个吗?并继承?

设计模式的 Java 注释?