【发布时间】:2018-09-24 01:45:18
【问题描述】:
我有以下聚合:
- 结帐(根)
- 要求:CouponRequirement、AnotherRequirement、YetAnotherRequirement
- 优惠券
Checkout 有许多 Requirements 需要满足才能完成 Checkout。
每个Requirement 都有一个fulfill(data) 方法负责实现过程。
其中一个要求是CouponRequirement,当它满足时,需要确保有特定优惠券的库存并保留它。
为此,我需要访问 CouponRepository 或 CouponService。
如何调整我的设计以适应这种依赖关系?
FulfillRequirementCommand
function handle($cmd) {
$cho = $this->checkoutRepository->get($cmd->checkoutId);
$cho->fulfillRequirement($cmd->requirementType, $cmd->requirementData);
}
结帐
function fulfillRequirement($reqType, $reqData) {
$req = $this->getRequirement($reqType);
$req->fulfill($reqData);
}
优惠券要求
function fulfill($data) {
// check stock / reserve coupon
}
【问题讨论】: