QtDesignPatterns/commandpattern/interface.h

35 lines
452 B
C++

#include "stock.h"
class Order
{
public:
Order(){}
virtual ~Order(){}
virtual void execute() = 0;
};
class BuyStock: public Order
{
public:
BuyStock(Stock *stock) : stock(stock){}
void execute()
{
stock->buy();
}
private:
Stock *stock;
};
class SellStock: public Order
{
public:
SellStock(Stock *stock) : stock(stock){}
void execute()
{
stock->sell();
}
private:
Stock *stock;
};