Re: Many rules for reusability and testability

"Greg Young [email protected] [domaindrivendesign]" <[email protected]> Thu, 18 Dec 2014 12:22:51 +0000
Newsgroups gmane.comp.programming.domain-driven-design
Message-ID <CAC9RQtgG=VQKJRzuW6+fEN0d400eFs7ouGkqcrBm+NUoqbgJog@mail.gmail.com>
Send an "eviction" to the BRE to have it run its business rules via say an
infrastructure service.

var rulesbroken = ExternalRuleService.Validate(eviction)

Good luck on keeping the BRE tested though.The moment you say "we will
externally have business rules entered by business people" the concept of
testing tends to go out the window.

Greg

On Thu, Dec 18, 2014 at 12:12 PM, [email protected]
[domaindrivendesign] <[email protected]> wrote:
>
>
>
> I have problem similar to this where I need to decide how to deal numerous
> rules.
>
>
> I own *10 houses*. There are *10 renters*. At the end of the month, I
> check whether all the 10 renters have paid their rent. If they have not
> paid their rent, I have to send an eviction notice. There are many rules to
> be checked before sending the eviction notice.
>
>
> 1. Have I sent a reminder to the renter to pay the rent before the end of
> the month?
>
> 2. Have I given the renter a grace period of 5 days after the reminder was
> sent?
>
> 3. Whether or not the renter has his furniture in the house? If he does
> not have, send the eviction notice immediately else send a warning
> notification with 10 days grace period.
>
> 4. Is the renter living in the house for more than 5 years? If so, send a
> warning notification with a 30 days grace period to pay the rent.
>
> 5. ...
>
>
> I can think of two entities here *OWNER* and *RENTER*. I can also think
> about
>
>
> Owner owner = new Owner();
>
> Renter renter = new Renter();
>
> if (owner.Evict(renter))
>
> {
>
> // Let the UI know the renter has been evicted after checking all the
> rules.
>
> }
>
> else
>
> {
>
> // Let the UI know the renter has not been evicted because certain rules
> failed like the renter has not been sent // a reminder.
>
> }
>
>
> There can be numerous rules to meet the *Evict* behavior. They are agile,
> so it can change during the development. They also need to be tested.
>
>
> When I looked at some DDD examples, I see that the rules like these are
> baked into the Evict method. Adding a new rule requires the module that
> holds he Evict method need to be compiled. I would rather test *HasRenterBeenSentAReminder
> *rather than a *Evict* method.
>
>
> What pattern I can follow to implement a kind of Business Rules Engine in
> DDD?
>
>
> Thanks.
>
>
>  
>


-- 
Studying for the Turing test