This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import annotations | |
| from abc import ABC, abstractmethod | |
| from typing import Any, Optional | |
| class Handler(ABC): | |
| """ | |
| Интерфейс Обработчика объявляет метод построения цепочки обработчиков. Он | |
| также объявляет метод для выполнения запроса. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import ABC, abstractmethod | |
| class Subject(ABC): | |
| """ | |
| Интерфейс Субъекта объявляет общие операции как для Реального Субъекта, так | |
| и для Заместителя. Пока клиент работает с Реальным Субъектом, используя этот | |
| интерфейс, вы сможете передать ему заместителя вместо реального субъекта. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from typing import Dict | |
| class Flyweight: | |
| """ | |
| Легковес хранит общую часть состояния (также называемую внутренним | |
| состоянием), которая принадлежит нескольким реальным бизнес-объектам. | |
| Легковес принимает оставшуюся часть состояния (внешнее состояние, уникальное | |
| для каждого объекта) через его параметры метода. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import ABC, abstractmethod | |
| class DataSource(ABC): | |
| @abstractmethod | |
| def write_data(self): | |
| pass | |
| @abstractmethod | |
| def read_data(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Remote: | |
| def __init__(self, device): | |
| self.device = device | |
| def volumeDown(self): | |
| volume_now = self.device.getVolume() | |
| volume_new = volume_now - 10 | |
| self.device.setVolume(volume_new) |