【发布时间】:2018-12-19 10:02:42
【问题描述】:
假设我们将提升作为聚合根和规则来满足作为聚合的提升。 规则是扩展抽象类规则的不同规则元素的集合。
据我所知,我可以使用工厂方法,例如:
class Promotion (
PromotionIdentity $identity,
string $name,
){
$this->identity = $identity;
$this->name = $name;
$this->rules = new RuleCollection();
}
public function addRule(
RuleIdentity $ruleIdentity,
RuleType $ruleType,
array $configuration
) {
if (RuleType::EMAIL_LIST === $ruleType->value()) {
$makeRule = new EmailListRule($ruleIdentity, $configuration);
$this->rules->add($makeRule);
}
if (RuleType::MIN_ARTICLES === $ruleType->value()) {
$makeRule = new MinimumArticlesRule($ruleIdentity, $configuration);
$this->rules->add($makeRule);
}
... and so on, for example 15 rules
}
我认为这可以增长很多,我在这里看到了代码的味道。
把这个创建规则的逻辑保留在聚合根中可以吗?我们可以把这个创建规则的责任转移到工厂内的应用程序服务上,并将构建的规则传递给 addRule 方法吗?其他选择?谢谢朋友!
【问题讨论】:
标签: java php oop domain-driven-design aggregateroot