QtDesignPatterns/strategypattern/interface.h

35 lines
526 B
C
Raw Permalink Normal View History

2024-02-06 17:21:37 +08:00
class Strategy
{
public:
Strategy(){}
virtual ~Strategy(){}
virtual int doOperation(int num1, int num2) = 0;
};
class OperationAdd : public Strategy
{
public:
int doOperation(int num1, int num2)
{
return num1 + num2;
}
};
class OperationSubstract: public Strategy
{
public:
int doOperation(int num1, int num2)
{
return num1 - num2;
}
};
class OperationMultiply: public Strategy
{
public:
int doOperation(int num1, int num2)
{
return num1 * num2;
}
};