2626 * Aa1 Aa2 Ab1 Ab2
2727 */
2828
29-
3029/* *
3130 * EN: The Implementation defines the interface for all implementation classes.
3231 * It doesn't have to match the Abstraction's interface. In fact, the two
4140 * определяет операции более высокого уровня, основанные на этих примитивах.
4241 */
4342
44- class Implementation
45- {
46- public:
47- virtual ~Implementation (){}
48- virtual std::string OperationImplementation () const =0 ;
43+ class Implementation {
44+ public:
45+ virtual ~Implementation () {}
46+ virtual std::string OperationImplementation () const = 0;
4947};
5048
51-
5249/* *
5350 * EN: Each Concrete Implementation corresponds to a specific platform and
5451 * implements the Implementation interface using that platform's API.
5552 *
5653 * RU: Каждая Конкретная Реализация соответствует определённой платформе и
5754 * реализует интерфейс Реализации с использованием API этой платформы.
5855 */
59- class ConcreteImplementationA : public Implementation
60- {
61- public:
62- std::string OperationImplementation ()const override
63- {
64- return " ConcreteImplementationA: Here's the result on the platform A.\n " ;
65- }
56+ class ConcreteImplementationA : public Implementation {
57+ public:
58+ std::string OperationImplementation () const override {
59+ return " ConcreteImplementationA: Here's the result on the platform A.\n " ;
60+ }
6661};
67- class ConcreteImplementationB : public Implementation
68- {
69- public:
70- std::string OperationImplementation ()const override
71- {
72- return " ConcreteImplementationB: Here's the result on the platform B.\n " ;
73- }
62+ class ConcreteImplementationB : public Implementation {
63+ public:
64+ std::string OperationImplementation () const override {
65+ return " ConcreteImplementationB: Here's the result on the platform B.\n " ;
66+ }
7467};
7568
7669/* *
@@ -83,48 +76,41 @@ class ConcreteImplementationB: public Implementation
8376 * ему всю настоящую работу.
8477 */
8578
86- class Abstraction {
87- /* *
79+ class Abstraction {
80+ /* *
8881 * @var Implementation
8982 */
90- protected:
91- Implementation* implementation_;
92-
93- public:
83+ protected:
84+ Implementation* implementation_;
9485
95- Abstraction (Implementation* implementation):implementation_(implementation){
96- }
97-
98- virtual ~Abstraction (){
86+ public:
87+ Abstraction (Implementation* implementation) : implementation_(implementation) {
88+ }
9989
100- }
90+ virtual ~Abstraction () {
91+ }
10192
102- virtual std::string Operation () const {
103- return " Abstraction: Base operation with:\n " +
104- this ->implementation_ ->OperationImplementation ();
105- }
93+ virtual std::string Operation () const {
94+ return " Abstraction: Base operation with:\n " +
95+ this ->implementation_ ->OperationImplementation ();
96+ }
10697};
10798/* *
10899 * EN: You can extend the Abstraction without changing the Implementation
109100 * classes.
110101 *
111102 * RU: Можно расширить Абстракцию без изменения классов Реализации.
112103 */
113- class ExtendedAbstraction : public Abstraction
114- {
115- public:
116-
117- ExtendedAbstraction (Implementation* implementation): Abstraction(implementation){
118-
119- }
120- std::string Operation () const override
121- {
122- return " ExtendedAbstraction: Extended operation with:\n " +
123- this ->implementation_ ->OperationImplementation ();
124- }
104+ class ExtendedAbstraction : public Abstraction {
105+ public:
106+ ExtendedAbstraction (Implementation* implementation) : Abstraction(implementation) {
107+ }
108+ std::string Operation () const override {
109+ return " ExtendedAbstraction: Extended operation with:\n " +
110+ this ->implementation_ ->OperationImplementation ();
111+ }
125112};
126113
127-
128114/* *
129115 * EN: Except for the initialization phase, where an Abstraction object gets
130116 * linked with a specific Implementation object, the client code should only
@@ -136,11 +122,10 @@ class ExtendedAbstraction : public Abstraction
136122 * класса Абстракции. Таким образом, клиентский код может поддерживать любую
137123 * комбинацию абстракции и реализации.
138124 */
139- void ClientCode (const Abstraction& abstraction)
140- {
141- // ...
142- std::cout << abstraction.Operation ();
143- // ...
125+ void ClientCode (const Abstraction& abstraction) {
126+ // ...
127+ std::cout << abstraction.Operation ();
128+ // ...
144129}
145130/* *
146131 * EN: The client code should be able to work with any pre-configured
@@ -150,22 +135,20 @@ void ClientCode(const Abstraction& abstraction)
150135 * комбинацией абстракции и реализации.
151136 */
152137
153- int main (){
154-
155- Implementation* implementation = new ConcreteImplementationA;
156- Abstraction* abstraction = new Abstraction (implementation);
157- ClientCode (*abstraction);
158- std::cout << std::endl;
159- delete implementation;
160- delete abstraction;
138+ int main () {
139+ Implementation* implementation = new ConcreteImplementationA;
140+ Abstraction* abstraction = new Abstraction (implementation);
141+ ClientCode (*abstraction);
142+ std::cout << std::endl;
143+ delete implementation;
144+ delete abstraction;
161145
162- implementation = new ConcreteImplementationB;
163- abstraction = new ExtendedAbstraction (implementation);
164- ClientCode (*abstraction);
146+ implementation = new ConcreteImplementationB;
147+ abstraction = new ExtendedAbstraction (implementation);
148+ ClientCode (*abstraction);
165149
166- delete implementation;
167- delete abstraction;
150+ delete implementation;
151+ delete abstraction;
168152
169- return 0 ;
153+ return 0 ;
170154}
171-
0 commit comments