June 2017
Intermediate to advanced
536 pages
9h 49m
English
The object pool pattern manages class instances--objects. It is used in situations where we would like to limit unnecessary class instantiation due to resource-intense operations. The object pool acts much like a registry for objects, from which clients can pick up necessary objects later on.
The following example demonstrates a possible object pool pattern implementation:
<?phpclass ObjectPool{ private $instances = []; public function load($key) { return $this->instances[$key]; } public function save($object, $key) { $this->instances[$key] = $object; }}class User{ public function hello($name) { return 'Hello ' . $name; }}// Client use$pool = new ObjectPool();$user = new User();$key = spl_object_hash($user);$pool ...