Many rules for reusability and testability
| Newsgroups | gmane.comp.programming.domain-driven-design |
|---|---|
| Message-ID | <[email protected]> |
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.