aggregates-by-example icon indicating copy to clipboard operation
aggregates-by-example copied to clipboard

PHP examples - Availability - Policies seems to be more like Specifications

Open ddziaduch opened this issue 4 years ago • 1 comments

Hi @mariuszgil, @pilloPl.

Thanks for this great repository!

First of all, I am not a big expert of DDD.

But, your Policies are doing one thing, they are just checking whether some conditions are satisfied. This looks like a Specification pattern from the Blue Book.

The Policies in the Blue Book are something quite like Strategy pattern, they are encapsulating some logic, for e.g. you can have a Policy which gives some discount based on some condition. So they are doing things, not just checking things.

I found on a thread about think topic on StackOverFlow which explains this very well: https://stackoverflow.com/questions/14185139/difference-between-specification-and-a-policy

I'd like to learn something here, I know this is just naming, but I am curious about this one 🙂

Regards, Damian

ddziaduch avatar Apr 29 '20 11:04 ddziaduch

Hey @ddziaduch! When I was implementing this archetype in one of my project I was wondering about same thing - where to put those simple "specification" rules? In that case I though about it as a POLICY that uses SPECIFICATION pattern.

In module description check the employee path and the difference how it deals with cleaning. https://github.com/mariuszgil/aggregates-by-example/blob/master/examples/example-availability-resource.md

I guess that "no overlapping", "limited duration" an "no gaps between" are not "hard" specification. It keep code open for changes like:

  • if you reserve today - we don't care about gaps - just book something;
  • if it's employee there is no "limited duration";
  • our CEO can overlap everything!

And some quotes from the link you gave:

Some validation POLICY can use SPECIFICATIONs to check that the requirements are satisfied, of course.

So you can have many SPECIFICATIONs in your project, but a manageable number of POLICIES, and those POLICIES should be easy to find and to change.

I'd love to know what @mariuszgil and @pilloPl thinks about it too.

Cheers!

P.S. Sorry for digging this issue out but it's quite interesting question. 😃

speccode avatar Jul 24 '21 21:07 speccode