5. Client
(Domain expert)
Project Manager Developer
We need to add a new
security policy to our
accounts. Our customers
can’t have more than two
active offers per billing term.
We need to restrict
promotions. A user cannot
have more than two
promotions per month.
public function validate(User $user)
{
// … other crazy validations
if (count ($user->getPromotions()) > 2)
throw new ValidationException(
“User can’t have more than 2
promotions per month”
);
// … continue with crazy validations
}
7. Client
(Domain expert)
Project Manager Developer
We need to add a new
security policy to our
accounts. Our customers
can’t have more than two
active offers per billing term.
public function validate(Account $account)
{
// … other crazy validations
if (! $account->satisfies(
new ActiveOffersPerBillingTermSecurityPolicy
))
throw new ValidationException(
“Account did not satisfy the active offers
security policy”
);
// … continue with crazy validations
}
12. Favor model language
over translations
When a domain expert (client) feels something’s wrong with the model
language, you’ll know something’s wrong with the domain model.
13. Client
(Domain expert)
Project Manager Developer
When we talk about a billing
term, we need to consider if
the customer is billed on a
monthly or yearly basis.
| class ActiveOffersPerBillingTermSecurityPolicy
| {
| protected $maxOffers = 2;
|
| public function isSatisfiedBy(Account $account)
| {
| return count(
- | $account->getMonthlyOffers()
+ | $account->getOffersForBillingTerm()
| ) < $this->maxOffers;
| }
17. Client
(Domain expert)
class LongOverdueCustomerContactCommand
{
public function execute()
{
$customers = Customer::where(
‘account.balance’, ‘<’, 0
)->get();
foreach ($customers as $customer)
$this->sendRefinanceEmail($customer);
}
}
Project Manager Developer
We need to contact long
overdue customers to
refinance their debt.
18. Client
(Domain expert)
class LongOverdueCustomerContactCommand
{
public function execute()
{
$customers = Customer::where(
‘account.balance’, ‘<’, 0
)->get();
foreach ($customers as $customer)
$this->sendRefinanceEmail($customer);
}
}
Project Manager Developer
We need to contact long
overdue customers to
refinance their debt.
19. Client
(Domain expert)
Project Manager Developer
We need to contact long
overdue customers to
refinance their debt.
What is the difference
between a regular customer,
an overdue customer and a
long overdue customer?
20. Client
(Domain expert)
class CustomerRepository
{
public function findOverdue()
{
return Customer::where(‘account.balance’, ‘<’, 0)
->get();
}
public function findLongOverdue()
{
// Write more complex query logic for this one...
}
}
Project Manager Developer
Overdue is straightforward,
customers in debt right now.
Long overdue customers are
the ones that have been
overdue over the last 3
billing terms, at the end of
each billing term.