EN: Each Concrete Component must implement the `accept` method in such a way that it calls the visitor's method corresponding to the component's class. RU: Каждый Конкретный Компонент должен реализовать метод accept таким образом, чтобы он вызывал метод посетителя, соответствующий
| 30 | |
| 31 | |
| 32 | class ConcreteComponentA(Component): |
| 33 | """ |
| 34 | EN: Each Concrete Component must implement the `accept` method in such a way |
| 35 | that it calls the visitor's method corresponding to the component's class. |
| 36 | |
| 37 | RU: Каждый Конкретный Компонент должен реализовать метод accept таким |
| 38 | образом, чтобы он вызывал метод посетителя, соответствующий классу |
| 39 | компонента. |
| 40 | """ |
| 41 | |
| 42 | def accept(self, visitor: Visitor) -> None: |
| 43 | """ |
| 44 | EN: Note that we're calling `visitConcreteComponentA`, which matches the |
| 45 | current class name. This way we let the visitor know the class of the |
| 46 | component it works with. |
| 47 | |
| 48 | RU: Обратите внимание, мы вызываем visitConcreteComponentA, что |
| 49 | соответствует названию текущего класса. Таким образом мы позволяем |
| 50 | посетителю узнать, с каким классом компонента он работает. |
| 51 | """ |
| 52 | |
| 53 | visitor.visit_concrete_component_a(self) |
| 54 | |
| 55 | def exclusive_method_of_concrete_component_a(self) -> str: |
| 56 | """ |
| 57 | EN: Concrete Components may have special methods that don't exist in |
| 58 | their base class or interface. The Visitor is still able to use these |
| 59 | methods since it's aware of the component's concrete class. |
| 60 | |
| 61 | RU: Конкретные Компоненты могут иметь особые методы, не объявленные в их |
| 62 | базовом классе или интерфейсе. Посетитель всё же может использовать эти |
| 63 | методы, поскольку он знает о конкретном классе компонента. |
| 64 | """ |
| 65 | |
| 66 | return "A" |
| 67 | |
| 68 | |
| 69 | class ConcreteComponentB(Component): |