13. Anemic (Domain) Model
“In essence the problem with anemic domain
models is that they incur all of the costs of a domain
model, without yielding any of the benefits.”
Martin Fowler
http://www.martinfowler.com/bliki/AnemicDomainModel.html
http://habrahabr.ru/post/224879/
39. Domain Model
<?php
namespace MegaCorpCoreProduct;
class Product
{
private $id;
private $name;
private $recognitionStrategy;
public function __construct(
ProductId $id, $name, $recognitionStrategy
) {
$this->id = $id;
$this->name = $name;
$this->recognitionStrategy = $recognitionStrategy;
}
40. Repository
<?php
namespace MegaCorpCoreProduct;
interface ProductRepository
{
public function find(ProductId $productId);
public function findAll();
public function add(Product $product);
public function remove(Product $product);
}
41. Value Object
<?php
namespace MegaCorpCore;
class ProductId
{
private $value;
public function __construct($value)
{
$this->value = (string) $value;
}
public function getValue()
{
return $this->value;
}
}
43. Value Object DateRange
<?php
public function findByDateRange(
DateTime $from, DateTime $to )
class DateRange
{
private $from;
private $to;
public function __construct(DateTime $from, DateTime $to)
{
$this->from = $from;
$this->to = $to;
}
}
public function findByDateRange(DateRange $range)