From d9d3f1213213ef6659aa1f200ba117d2534d1640 Mon Sep 17 00:00:00 2001 From: Dominik Liebler Date: Thu, 7 Apr 2016 08:53:37 +0200 Subject: [PATCH] added README.rst to FlyweightFactory --- Structural/Flyweight/FlyweightFactory.php | 5 +++ Structural/Flyweight/README.rst | 51 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Structural/Flyweight/README.rst diff --git a/Structural/Flyweight/FlyweightFactory.php b/Structural/Flyweight/FlyweightFactory.php index 6f70372..a15a07b 100644 --- a/Structural/Flyweight/FlyweightFactory.php +++ b/Structural/Flyweight/FlyweightFactory.php @@ -12,12 +12,14 @@ class FlyweightFactory { /** * Associative store for flyweight objects + * * @var Array */ private $pool = array(); /** * Magic getter + * * @param string $name * @return Flyweight */ @@ -29,6 +31,9 @@ class FlyweightFactory return $this->pool[$name]; } + /** + * @return int + */ public function totalNumber() { return sizeof($this->pool); diff --git a/Structural/Flyweight/README.rst b/Structural/Flyweight/README.rst new file mode 100644 index 0000000..322ebad --- /dev/null +++ b/Structural/Flyweight/README.rst @@ -0,0 +1,51 @@ +`Flyweight`__ +========== + +Purpose +------- + +To minimise memory usage, a Flyweight shares as much as possible memory with similar objects. It +is needed when a large amount of objects is used that don't differ much in state. A common practice is +to hold state in external data structures and pass them to the flyweight object when needed. + +UML Diagram +----------- + +.. image:: uml/uml.png + :alt: Alt Facade UML Diagram + :align: center + +Code +---- + +You can also find these code on `GitHub`_ + +FlyweightInterface.php + +.. literalinclude:: FlyweightInterface.php + :language: php + :linenos: + +CharacterFlyweight.php + +.. literalinclude:: CharacterFlyweight.php + :language: php + :linenos: + +FlyweightFactory.php + +.. literalinclude:: FlyweightFactory.php + :language: php + :linenos: + +Test +---- + +Tests/FlyweightTest.php + +.. literalinclude:: Tests/FlyweightTest.php + :language: php + :linenos: + +.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/Flyweight +.. __: https://en.wikipedia.org/wiki/Flyweight_pattern