Flyweight Design Pattern
Videos
| Section | Video Links |
|---|---|
| Flyweight Overview | ![]() |
| Flyweight Use Case | ![]() |
| String Justification | ![]() |
Book
Overview
... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.
Terminology
... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.
Flyweight UML Diagram
Source Code
... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.
Output
python ./flyweight/flyweight_concept.py abracadabra abracadabra has 11 letters FlyweightFactory has 5 flyweights
Example Use Case
... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.
Example UML Diagram
Output
python ./flyweight/client.py ----------------------------------------- |abra | 112233 | cadabra| |racadab | 12345 | 332211| |cadabra | 445566 | aa 22 bb| ----------------------------------------- FlyweightFactory has 12 flyweights
New Coding Concepts
String Justification
In /flyweight/column.py, there are commands center(), ljust() and rjust() .
These are special commands on strings that allow you to pad strings and align them left, right, center depending on total string length.
eg,
>>> "abcd".center(10) ' abcd '
>>> "abcd".rjust(10) ' abcd'
>>> "abcd".ljust(10) 'abcd '
Summary
... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.



