Strategy
#include
using namespace std;
//Behavior interface
class IBehavior
{
public:
virtual string GetResponse(string szInput) = 0;
};
//strategies
class Asshole : public IBehavior
{
string GetResponse(string szInput){
return "*%&_%# you and the horse you rode in on!!\n";
}
};
class Cool : public IBehavior
{
string GetResponse(string szInput){
return "I think your statement \"" + szInput + "\" is very interesting\n";
}
};
class Shy : public IBehavior
{
string GetResponse(string szInput){
return "squeak\n";
}
};
// user of strategies
class Person
{
public:
string Respond(string szInput){
return m_pBehavior->GetResponse(szInput);
}
IBehavior* m_pBehavior;
};
int main()
{
cout << "Class: main, Method: main\n" << endl << endl;
Person person1;
person1.m_pBehavior = new Shy();
Person person2;
person2.m_pBehavior = new Cool();
Person person3;
person3.m_pBehavior = new Asshole();
string szStatement = "its only photons hitting the eye";
cout << szStatement << endl << endl;
cout << person1.Respond(szStatement) << endl;
cout << person2.Respond(szStatement) << endl;
cout << person3.Respond(szStatement) << endl;
cout << endl;
}