DesignPattern/24.VisitorPattern/2.Code/Element.h

57 lines
808 B
C
Raw Normal View History

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(){};
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