Skip to content

Commit d9d3f12

Browse files
author
Dominik Liebler
committed
added README.rst to FlyweightFactory
1 parent b8e602f commit d9d3f12

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Structural/Flyweight/FlyweightFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ class FlyweightFactory
1212
{
1313
/**
1414
* Associative store for flyweight objects
15+
*
1516
* @var Array
1617
*/
1718
private $pool = array();
1819

1920
/**
2021
* Magic getter
22+
*
2123
* @param string $name
2224
* @return Flyweight
2325
*/
@@ -29,6 +31,9 @@ public function __get($name)
2931
return $this->pool[$name];
3032
}
3133

34+
/**
35+
* @return int
36+
*/
3237
public function totalNumber()
3338
{
3439
return sizeof($this->pool);

Structural/Flyweight/README.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
`Flyweight`__
2+
==========
3+
4+
Purpose
5+
-------
6+
7+
To minimise memory usage, a Flyweight shares as much as possible memory with similar objects. It
8+
is needed when a large amount of objects is used that don't differ much in state. A common practice is
9+
to hold state in external data structures and pass them to the flyweight object when needed.
10+
11+
UML Diagram
12+
-----------
13+
14+
.. image:: uml/uml.png
15+
:alt: Alt Facade UML Diagram
16+
:align: center
17+
18+
Code
19+
----
20+
21+
You can also find these code on `GitHub`_
22+
23+
FlyweightInterface.php
24+
25+
.. literalinclude:: FlyweightInterface.php
26+
:language: php
27+
:linenos:
28+
29+
CharacterFlyweight.php
30+
31+
.. literalinclude:: CharacterFlyweight.php
32+
:language: php
33+
:linenos:
34+
35+
FlyweightFactory.php
36+
37+
.. literalinclude:: FlyweightFactory.php
38+
:language: php
39+
:linenos:
40+
41+
Test
42+
----
43+
44+
Tests/FlyweightTest.php
45+
46+
.. literalinclude:: Tests/FlyweightTest.php
47+
:language: php
48+
:linenos:
49+
50+
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/Flyweight
51+
.. __: https://en.wikipedia.org/wiki/Flyweight_pattern

0 commit comments

Comments
 (0)