mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-05-13 09:56:21 +02:00
unifies indentation
This commit is contained in:
parent
d779b1e86a
commit
6e937055cf
@ -5,7 +5,7 @@ namespace DesignPatterns\Pool;
|
||||
class Pool
|
||||
{
|
||||
|
||||
private $instances = array();
|
||||
private $instances = array();
|
||||
private $class;
|
||||
|
||||
public function __construct($class)
|
||||
@ -13,19 +13,18 @@ class Pool
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
if (count($this->instances) > 0) {
|
||||
return array_pop($this->instances);
|
||||
}
|
||||
public function get()
|
||||
{
|
||||
if (count($this->instances) > 0) {
|
||||
return array_pop($this->instances);
|
||||
}
|
||||
|
||||
return new $this->class();
|
||||
}
|
||||
return new $this->class();
|
||||
}
|
||||
|
||||
public function dispose($instance)
|
||||
{
|
||||
$this->instances[] = $instance;
|
||||
}
|
||||
public function dispose($instance)
|
||||
{
|
||||
$this->instances[] = $instance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -51,4 +51,3 @@ class Processor
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,4 +6,3 @@ The **object pool pattern** is a software creational design pattern that uses a
|
||||
Object pooling can offer a significant performance boost in situations where the cost of initializing a class instance is high, the rate of instantiation of a class is high, and the number of instances in use at any one time is low. The pooled object is obtained in predictable time when creation of the new objects (especially over network) may take variable time.
|
||||
|
||||
However these benefits are mostly true for objects that are expensive with respect to time, such as database connections, socket connections, threads and large graphic objects like fonts or bitmaps. In certain situations, simple object pooling (that hold no external resources, but only occupy memory) may not be efficient and could decrease performance.
|
||||
|
||||
|
@ -11,12 +11,11 @@ class Worker
|
||||
// for example creates "thread"
|
||||
}
|
||||
|
||||
public function run($image, array $callback)
|
||||
{
|
||||
public function run($image, array $callback)
|
||||
{
|
||||
// do something with $image...
|
||||
// and when it's done, execute callback
|
||||
call_user_func($callback, $this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,4 +14,3 @@ $processor->process('image5.jpg');
|
||||
$processor->process('image6.jpg');
|
||||
$processor->process('image7.jpg');
|
||||
$processor->process('image8.jpg');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user