Answer the question
In order to leave comments, you need to log in
Am I understanding the prototype pattern correctly?
class ResponseClassPrototype extends PrototypeAbstract implements Clonable {
private $proto = null;
public function __construct(Response $class)
{
$this->proto = $class;
}
public function getClone()
{
return clone $this->proto();
};
public function json()
{
$response = $this->getClone();
$response->setHeader('Content-type', 'application/json');
return $response;
}
//function html();
// ...
}
Answer the question
In order to leave comments, you need to log in
Have you read exactly what kind of pattern this is and how it differs from the factory?
In general, you can answer the question if you give an example of using this pattern. Well, also consider this point - in your example, using a prototype is not rational - cloning objects such as request is not very expensive.
ps the `getClone` method must be private. Everything else seems to be ok.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question