Last active
December 15, 2015 08:29
-
-
Save a-suenami/5231617 to your computer and use it in GitHub Desktop.
PHPでDDD(ドメイン駆動設計)やるにはどうすればいいのか考え中。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AbstractEntity implements EntityInterface | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface EntityInterface | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface RepositoryInterface | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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