Skip to content

Instantly share code, notes, and snippets.

@yoye
Last active October 16, 2015 14:03
Show Gist options
  • Save yoye/7c2d2cbdca758a08346c to your computer and use it in GitHub Desktop.
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 ?
<?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