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: Легковес хранит общую часть
| 18 | |
| 19 | |
| 20 | class 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 | |
| 42 | class FlyweightFactory(): |
no outgoing calls
no test coverage detected