Skip to content

Instantly share code, notes, and snippets.

@a-suenami
Last active December 15, 2015 08:29
Show Gist options
  • Save a-suenami/5231617 to your computer and use it in GitHub Desktop.
Save a-suenami/5231617 to your computer and use it in GitHub Desktop.
PHPでDDD(ドメイン駆動設計)やるにはどうすればいいのか考え中。
<?php
class AbstractEntity implements EntityInterface
{
}
<?php
abstract class ValueObject
{
private $value;
private static $instances = array();
private function __construct($value)
{
if (!$this->assert($value)) throw new \Exception("invalid value: {$value}");
$this->value = $value;
}
public static function getInstance($value)
{
if (!isset(self::$instances[$value])) {
$class_name = get_called_class();
self::$instances[$value] = new $class_name($value);
}
return self::$instances[$value];
}
abstract public function assert($value);
abstract public function toString();
}
<?php
interface EntityInterface
{
}
<?php
interface RepositoryInterface
{
}
<?php
interface SpecificationInterface
{
public function isSatisfiedBy(EntityInterface $entity);
public function satisfyingElementsFrom(RepositoryInterface repository);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment