PHP7 Builder

This commit is contained in:
Dominik Liebler
2016-09-22 13:51:35 +02:00
parent 9f42521e8f
commit 7beb1420b4
3 changed files with 3 additions and 9 deletions

View File

@@ -0,0 +1,30 @@
<?php
namespace DesignPatterns\Creational\Pool;
class Pool
{
private $instances = [];
private $class;
public function __construct($class)
{
$this->class = $class;
}
public function get()
{
if (count($this->instances) > 0) {
return array_pop($this->instances);
}
return new $this->class();
}
public function dispose($instance)
{
$this->instances[] = $instance;
}
}