Skip to content

Commit cde989f

Browse files
authoredJul 14, 2018
Merge pull request faif#235 from GiantsLoveDeathMetal/add-flyweight-description
Add description to the flyweight pattern
2 parents e5b595a + e3228c3 commit cde989f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎structural/flyweight.py

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
# -*- coding: utf-8 -*-
33

44
"""
5+
*What is this pattern about?
6+
This pattern aims to minimise the number of objects that are needed by
7+
a program at run-time. A Flyweight is an object shared by multiple
8+
contexts, and is indistinguishable from an object that is not shared.
9+
10+
The state of a Flyweight should not be affected by it's context, this
11+
is known as its intrinsic state. The decoupling of the objects state
12+
from the object's context, allows the Flyweight to be shared.
13+
14+
*What does this example do?
15+
The example below sets-up an 'object pool' which stores initialised
16+
objects. When a 'Card' is created it first checks to see if it already
17+
exists instead of creating a new one. This aims to reduce the number of
18+
objects initialised by the program.
19+
520
*References:
621
http://codesnipers.com/?q=python-flyweights
722

0 commit comments

Comments
 (0)
Please sign in to comment.