QtDesignPatterns/commandpattern/interface.h

35 lines
452 B
C
Raw Normal View History

2024-02-06 17:21:37 +08:00
#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;
};