使用 DDD 建模时间表
我正在尝试为我的公司构建调度应用程序模型,并且可以使用一些建议。如果合适的话,我想遵循领域驱动的设计。
该域由一个 Show 对象组成,该对象代表我们可能推销我们产品的一个贸易展览、展览或会议。它有开始和结束日期和时间、议程、演讲者列表、地点等。展会可以完成很多工作,例如分配演讲者、注册与会者、取消等。
我们通常参加展会作为一项或多项营销活动的一部分。活动还包含开始和结束日期以及其他信息以及我们将参加该活动的演出列表。我们可能会在一场特定的展会上推广多个活动。
可以在活动中添加或删除节目,当取消节目时,必须将其从与其关联的任何活动中删除。
我的第一个想法是拥有一个 Schedule 聚合根,其中包含包含 Show 对象列表的 Campaign 实体列表。但我需要一种访问独立节目的方法 - 并且一个节目可以与多个营销活动相关联。
看看我的用例,我正在开发一个 Silverlight 客户端(但也可能会移动)。主视图将是一个日历类型的 UI(如 Outlook),将每个节目显示为约会。还有一些侧栏显示即将到来的节目、当前活动和具有后续任务的节目。当我双击任何这些视图中的某个项目时,“显示详细信息”将显示在子窗口中。
对于如何在我的应用程序代码中对该域进行建模有什么建议吗?
I am trying to model a scheduling application for my company and could use some suggestions. I'd like to follow a domain-driven design, if appropriate.
The domain consists of a Show object which represents one trade show, exhibition or conference where we may be promoting our products. It has start and end dates and times, an agenda, list of speakers, location, etc. Quite a bit of work can be done with the Show, such as assigning speakers, registering attendees, cancelling, etc.
We typically participate in a Show as part of one or more marketing Campaigns. 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. It is possible that we will be promoting more than one Campaign at a given 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.
My first thought was to have a Schedule aggregate root with a list of Campaign entities that contained a list of Show objects. But I need a way to access stand-alone Shows - and a Show can be associated with more than one Campaign.
Looking at my use cases, I am developing a Silverlight client (but may also go mobile). The main view will be a calendar-type UI (like Outlook) that displays each Show as an appointment. There are also side bars that display Upcoming Shows, Current Campaigns and Shows that have follow-up tasks. When I double-click an item in any of these views, the Show details are displayed in a child window.
Any suggestions how to model this domain in my application code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要尝试将所有内容都放在 Schedule 聚合根(当您自由谈论域时,在您的语言中不会出现的术语)下,而是尝试拥有 2 个聚合根 - Show 和 Campaign。
Campaign 可能没有必要保留对 Show 的引用。如果节目知道它促销的活动,那么当您显示活动信息时就足以找到它。
不,不应该。
演出应标记为已取消,如有必要,活动将隐藏它。
我会从this之类的东西开始。
很可能存在要求在您的域模型中引入 Schedule 的要求。但由于我还没有听到它(或者对您的域的理解不够好),我只是将我的应用程序命名为 Scheduler。或者调度程序有界上下文,如果应用程序不仅仅是调度节目和活动。
如果 Show 必须存在于“独立版本”中,那么它就是一个聚合根(将其推到 Schedule 下不会改变任何事情,只会添加一个抽象层。Show 仍然独立于 Campaign)。如果需要找出与“独立版本”中的节目相关联的活动,则应该存在关联“节目”->“活动”。尽管这可能感觉与领域有点矛盾,但您可以将其视为一种牺牲。
我们以清晰的原始想法来交换表达自己的能力(不确定性原理可以用作一个很好的类比这里)。毕竟——无论如何我们都无法完全彻底地捕捉心理模型。
您应该稍微关注域对象的生命周期。
物体的构建和重建之间存在巨大差异。通常,Campaign 只会构建一次,之后 - 它只会从数据存储中重建。如果您确保同一营销活动的不同实例(从域角度来看)不能保存两次 - 通常这就足够了。
是的...你是对的。
Instead of trying to put everything underneath Schedule aggregate root (term that does not appear in your language when you talk about domain freely), try having 2 aggregate roots - Show and Campaign.
It might be unnecessary for Campaign to hold reference to Show. If show knows Campaigns it promotes, that is enough to find it when you will be displaying Campaign information.
No, it should not.
Show should be marked as canceled and campaigns would just hide it if necessary.
I would start with something like this.
Quite likely there are requirement that asks for introduction of Schedule in Your domain model. But since I didn't hear it yet (or didn't understand Your domain good enough), I would just name my application as Scheduler. Or Scheduler bounded context, if application is more than about scheduling shows and campaigns.
If Show must exist in "stand-alone version", it's an aggregate root (pushing it down under Schedule would not change a thing, that would just add one more abstraction layer. Show would still be independent from Campaigns). If there is need to figure out Campaign/s Show is associated with while being seen as in "stand-alone version", there should be an association Show->Campaigns. Despite that it might feel a bit contradictory to domain, you can look at that as a sacrifice.
We trade ability to express ourselves with clearness of original idea (Uncertainty principle can be used as a great analogy here). After all - we can't capture mental models completely and thoroughly anyway.
You should focus a bit on life cycle of domain objects.
There is a huge difference between construction and reconstruction of an object. Typically, Campaign would be constructed once only, after that - it would be only reconstructed from data store. If you ensure that different instances of same Campaign (from domain perspective) can't be saved twice - usually that's enough.
Yap... You are right on this.