Last active
October 16, 2015 14:03
-
-
Save yoye/7c2d2cbdca758a08346c to your computer and use it in GitHub Desktop.
Is it a bad design to include a pseudo-specification in create method ?
This file contains hidden or 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 Foo | |
{ | |
public $name | |
public $value | |
public $bar; | |
public $baz; | |
} | |
class Factory | |
{ | |
private $repository; | |
public function __construct(Repository $repository) | |
{ | |
$this->repository = $repository; | |
} | |
public function create($name, $value) | |
{ | |
$object = $this->repository->findOneBy([ | |
'name' => $name, | |
'value' => $value, | |
]); | |
if ($object === null) { | |
$object = new Foo(); | |
$object->name = $name; | |
$object->value = $value; | |
} | |
return $object; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment