MCPcopy Create free account
hub / github.com/RefactoringGuru/design-patterns-python / Flyweight

Class Flyweight

src/Flyweight/Conceptual/main.py:20–39  ·  view source on GitHub ↗

EN: The Flyweight stores a common portion of the state (also called intrinsic state) that belongs to multiple real business entities. The Flyweight accepts the rest of the state (extrinsic state, unique for each entity) via its method parameters. RU: Легковес хранит общую часть

Source from the content-addressed store, hash-verified

18
19
20class Flyweight():
21 """
22 EN: The Flyweight stores a common portion of the state (also called
23 intrinsic state) that belongs to multiple real business entities. The
24 Flyweight accepts the rest of the state (extrinsic state, unique for each
25 entity) via its method parameters.
26
27 RU: Легковес хранит общую часть состояния (также называемую внутренним
28 состоянием), которая принадлежит нескольким реальным бизнес-объектам.
29 Легковес принимает оставшуюся часть состояния (внешнее состояние, уникальное
30 для каждого объекта) через его параметры метода.
31 """
32
33 def __init__(self, shared_state: str) -> None:
34 self._shared_state = shared_state
35
36 def operation(self, unique_state: str) -> None:
37 s = json.dumps(self._shared_state)
38 u = json.dumps(unique_state)
39 print(f"Flyweight: Displaying shared ({s}) and unique ({u}) state.", end="")
40
41
42class FlyweightFactory():

Callers 2

__init__Method · 0.85
get_flyweightMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected