1

I have the following aggregate:

  • Checkout (root)
  • Requirement: CouponRequirement, AnotherRequirement, YetAnotherRequirement
  • Coupon

A Checkout has many requirements that need to be fulfilled in order for a Checkout to complete. Each Requirement has a fulfill(data) method that is responsible for the fulfillment process.

One of those requirements is a CouponRequirement which, when fulfilled, needs to make sure there is stock for a particular coupon and reserve it. For this to happen I need access to a CouponRepository or CouponService.

How could I tailor my design to accomodate that dependency?

FulfillRequirementCommand

function handle($cmd) {
   $cho = $this->checkoutRepository->get($cmd->checkoutId);
   $cho->fulfillRequirement($cmd->requirementType, $cmd->requirementData);
}

Checkout

function fulfillRequirement($reqType, $reqData) {
    $req = $this->getRequirement($reqType);
    $req->fulfill($reqData);
}

CouponRequirement

function fulfill($data) {
    // check stock / reserve coupon
}

The common solution would be to pass a CouponService to fulfillRequirement. But fulfillRequirement takes care of many Requirement types, not just one.

Maybe I just need to abandon the generic approach and have multiple fulfillRequirement:

fulfillCouponRequirement($data, $couponService) fulfillClientInformationRequirement($data)

.. etc

What do you guys think? even if you think of a different approach altogether I'd love to read about it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.