您如何处理“默认”问题?当做DDD时

发布于 2024-08-24 11:17:25 字数 187 浏览 6 评论 0原文

我有兴趣了解人们在进行 DDD 时如何处理决策树。例如,我们有一个要求,当持久化特定类型的新实例时,必须构建一些“默认”关联(相当多)。不过,用户稍后可以自由更改它们。因此,如果创建一个决策表,您如何在您的领域中表示它,或者您这样做吗?这是在保险领域,因此例如,如果我选择一个选项,那么所有相关的“默认”福利、选项等都会添加到保单中,但用户稍后可以自由更改它。

I am interested to see how people deal with decision trees when doing DDD. For example we have a requirement that when persisting new instance of particular type, some "default" associations have to be built (quite a few). User is free to change them later on though. So if one creates a decision table, how do you represent this in you domain, or do you? This is in insurance domain, so for example, if I choose one option then all related "default" benefits, options etc, get added to the policy, but user is then free to change it later on.

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

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

发布评论

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

评论(2

筱果果 2024-08-31 11:17:25

这并不是 DDD 本身所特有的,您通常会使用 Factory 来实现它来创建您的默认聚合根。由于此行为是特定于业务的并且可能会发生变化,因此将对象创建的责任外部化给工厂比让聚合根本身处理此问题更好。

This is not specific to DDD per se, you would normally implement this using a Factory to create your default aggregate root. As this behavior is business specific and probably subject to change, externalizing the responsibility for object creation to the factory is better than letting the aggregate root deal with this itself.

橪书 2024-08-31 11:17:25

按照建议使用工厂。要实现默认设置,请使用 Martin Fowler 描述的“特殊情况模式”以获得真正的 OOP。

例如,如果您有一个包含 Benefit 和 Options 属性的策略,并且它们是类,则创建一个派生类,如下所示:

class Policy
{
Benefit Benefit {get;set;}
IList<Option> Options {get;set;}

//Factory
public static Policy CreateDefaultPolicy()
{
  var retVal = new Policy();
  retVal.Benefit = new DefaultBenefit();
  retVal.Options =new List<Options> ();
  retVal.Options.Add(DefaultLifeOption);
  retVal.Options.Add(DefaultCarOption);
  retun retVal;
}
}

class Benefit {}
class DefaultBenefit: Benefit {}

class Option{}
class DefaultLifeOption {}
class DefaultCarOption {}

As suggested use a factory. To implement the default use the "special case pattern" as described by Martin Fowler to have real OOP.

For example if you have a Policy with Benefit and Options properties and they are classes create a derived class like this:

class Policy
{
Benefit Benefit {get;set;}
IList<Option> Options {get;set;}

//Factory
public static Policy CreateDefaultPolicy()
{
  var retVal = new Policy();
  retVal.Benefit = new DefaultBenefit();
  retVal.Options =new List<Options> ();
  retVal.Options.Add(DefaultLifeOption);
  retVal.Options.Add(DefaultCarOption);
  retun retVal;
}
}

class Benefit {}
class DefaultBenefit: Benefit {}

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