36. class
Sale
{
(…)
private
$id;
!
function
__construct($name,
DateTimeInterface
$dueDate)
{
$this-‐>name
=
$name;
$this-‐>dueDate
=
$dueDate;
}
!
public
function
getId()
{
return
$this-‐>id;
}
}
37. class
Sale
{
(…)
public
function
activate()
{
if
(true
===
$this-‐>active)
{
throw
new
LogicException('Sale
already
activated!');
}
!
$this-‐>active
=
true;
}
}
39. class
Email
{
(…)
public
function
__construct($email)
{
if
(!filter_var($email,
FILTER_VALIDATE_EMAIL))
{
throw
new
InvalidArgumentException();
}
!
$this-‐>email
=
$email;
}
!
function
asString()
{
return
$this-‐>email;
}
}
43. interface
OrderRepository
{
public
function
save(Order
$order);
!
public
function
remove(Order
$order);
public
function
findById($orderId);
!
public
function
findObsolete();
}
44. class
DoctrineOrderRepository
implements
OrderRepository
{}
!
class
FileOrderRepository
implements
OrderRepository
{}
!
class
InMemoryOrderRepository
implements
OrderRepository
{}