Skip to content

Commit e3228c3

Browse files
author
GiantsLoveDeathMetal
committed
Add description to the flyweight pattern
1 parent e5b595a commit e3228c3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

structural/flyweight.py

Lines changed: 15 additions & 0 deletions
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)