Skip to content

Latest commit

 

History

History
 
 

flyweight

Flyweight Design Pattern

Videos

Section Video Links
Flyweight Overview Flyweight Overview Flyweight Overview Flyweight Overview
Flyweight Use Case Flyweight Use Case Flyweight Use Case Flyweight Use Case
String Justification String Justification String Justification String Justification

Book

Cover Links
Design Patterns In Python (ASIN : B08XLJ8Z2J)    https://www.amazon.com/dp/B08XLJ8Z2J
   https://www.amazon.co.uk/dp/B08XLJ8Z2J
   https://www.amazon.in/dp/B08Z282SBC
   https://www.amazon.de/dp/B08XLJ8Z2J
   https://www.amazon.fr/dp/B08XLJ8Z2J
   https://www.amazon.es/dp/B08XLJ8Z2J
   https://www.amazon.it/dp/B08XLJ8Z2J
   https://www.amazon.co.jp/dp/B08XLJ8Z2J
   https://www.amazon.ca/dp/B08XLJ8Z2J
   https://www.amazon.com.au/dp/B08Z282SBC

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

Flyweight Pattern 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

Flyweight Pattern Use Case 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.