Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 1.02 KB

README.rst

File metadata and controls

51 lines (35 loc) · 1.02 KB

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

Alt Flyweight UML Diagram

Code

You can also find this 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: