EN: The Abstract Class defines a template method that contains a skeleton of some algorithm, composed of calls to (usually) abstract primitive operations. Concrete subclasses should implement these operations, but leave the template method itself intact. RU: Абстрактный Кл
| 17 | |
| 18 | |
| 19 | class AbstractClass(ABC): |
| 20 | """ |
| 21 | EN: The Abstract Class defines a template method that contains a skeleton of |
| 22 | some algorithm, composed of calls to (usually) abstract primitive |
| 23 | operations. |
| 24 | |
| 25 | Concrete subclasses should implement these operations, but leave the |
| 26 | template method itself intact. |
| 27 | |
| 28 | RU: Абстрактный Класс определяет шаблонный метод, содержащий скелет |
| 29 | некоторого алгоритма, состоящего из вызовов (обычно) абстрактных примитивных |
| 30 | операций. |
| 31 | |
| 32 | Конкретные подклассы должны реализовать эти операции, но оставить сам |
| 33 | шаблонный метод без изменений. |
| 34 | """ |
| 35 | |
| 36 | def template_method(self) -> None: |
| 37 | """ |
| 38 | EN: The template method defines the skeleton of an algorithm. |
| 39 | |
| 40 | RU: Шаблонный метод определяет скелет алгоритма. |
| 41 | """ |
| 42 | |
| 43 | self.base_operation1() |
| 44 | self.required_operations1() |
| 45 | self.base_operation2() |
| 46 | self.hook1() |
| 47 | self.required_operations2() |
| 48 | self.base_operation3() |
| 49 | self.hook2() |
| 50 | |
| 51 | # EN: These operations already have implementations. |
| 52 | # |
| 53 | # RU: Эти операции уже имеют реализации. |
| 54 | |
| 55 | def base_operation1(self) -> None: |
| 56 | print("AbstractClass says: I am doing the bulk of the work") |
| 57 | |
| 58 | def base_operation2(self) -> None: |
| 59 | print("AbstractClass says: But I let subclasses override some operations") |
| 60 | |
| 61 | def base_operation3(self) -> None: |
| 62 | print("AbstractClass says: But I am doing the bulk of the work anyway") |
| 63 | |
| 64 | # EN: These operations have to be implemented in subclasses. |
| 65 | # |
| 66 | # RU: А эти операции должны быть реализованы в подклассах. |
| 67 | |
| 68 | @abstractmethod |
| 69 | def required_operations1(self) -> None: |
| 70 | pass |
| 71 | |
| 72 | @abstractmethod |
| 73 | def required_operations2(self) -> None: |
| 74 | pass |
| 75 | |
| 76 | # EN: These are "hooks." Subclasses may override them, but it's not |
nothing calls this directly
no outgoing calls
no test coverage detected