2019-11-10 14:59:08 +00:00
|
|
|
|
#ifndef __ELEMENT_H__
|
|
|
|
|
#define __ELEMENT_H__
|
|
|
|
|
|
|
|
|
|
#include "Visitor.h"
|
|
|
|
|
#include <iostream>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2021-10-28 15:15:51 +00:00
|
|
|
|
// 抽象元素
|
2019-11-10 14:59:08 +00:00
|
|
|
|
class Element
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Element(){};
|
2021-04-04 13:09:08 +00:00
|
|
|
|
virtual ~Element(){}
|
2019-11-10 14:59:08 +00:00
|
|
|
|
virtual void accept(Visitor*) = 0;
|
|
|
|
|
void setPrice(int iPrice){
|
|
|
|
|
this->price = iPrice;
|
|
|
|
|
}
|
|
|
|
|
int getPrice(){
|
|
|
|
|
return this->price;
|
|
|
|
|
}
|
|
|
|
|
void setNum(int iNum){
|
|
|
|
|
this->num = iNum;
|
|
|
|
|
}
|
|
|
|
|
int getNum(){
|
|
|
|
|
return num;
|
|
|
|
|
}
|
|
|
|
|
void setName(string iName){
|
|
|
|
|
this->name = iName;
|
|
|
|
|
}
|
|
|
|
|
string getName(){
|
|
|
|
|
return this->name;
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
int price;
|
|
|
|
|
int num;
|
|
|
|
|
string name;
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-28 15:15:51 +00:00
|
|
|
|
// 具体元素:Apple
|
2019-11-10 14:59:08 +00:00
|
|
|
|
class Apple :public Element
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Apple();
|
|
|
|
|
Apple(string name, int price);
|
|
|
|
|
void accept(Visitor*);
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-28 15:15:51 +00:00
|
|
|
|
// 具体元素:Book
|
2019-11-10 14:59:08 +00:00
|
|
|
|
class Book :public Element
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Book();
|
|
|
|
|
Book(string name, int price);
|
|
|
|
|
void accept(Visitor*);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|