Стратегия (шаблон проектирования): различия между версиями
[непроверенная версия] | [непроверенная версия] |
Содержимое удалено Содержимое добавлено
Строка 157:
{
public:
virtual ~Strategy(
virtual void use(void) = 0;
};
Строка 166 ⟶ 164 :
{
public:
void use(void){ std::cout << "Strategy_1" << std::endl; };
};
Строка 175 ⟶ 170 :
{
public:
void use(void){ std::cout << "Strategy_2" << std::endl; };
};
Строка 184 ⟶ 176 :
{
public:
void use(void){ std::cout << "Strategy_3" << std::endl; };
};
Строка 193 ⟶ 182 :
{
protected:
public:
virtual ~Context(
▲ virtual void UseStrategy(void) = 0;
▲ virtual void SetStrategy(Strategy* v) = 0;
};
class Client: public Context
{
{
operation->use();
}
void
{
operation = o;
Строка 220 ⟶ 204 :
};
int main
{
Client customClient;
Строка 227 ⟶ 211 :
Strategy_3 str3;
customClient.
customClient.
customClient.
customClient.
customClient.
customClient.
return 0;
Строка 249 ⟶ 233 :
struct Strategy_1
{
void
};
struct Strategy_2
{
void
};
struct Strategy_3
{
void
};
template <class Operation>
{
void useStrategy()
{
}
▲ this->do_method();
};
int main (int /*argc*/, char* /*argv*/[])
{
Client<Strategy_1> customClient1;
customClient1.
Client<Strategy_2> customClient2;
customClient2.
Client<Strategy_3> customClient3;
customClient3.
return 0;
|