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

56 lines
772 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;
// <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>
class Element
{
public:
Element(){};
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;
};
// <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD>أ<EFBFBD>Apple
class Apple :public Element
{
public:
Apple();
Apple(string name, int price);
void accept(Visitor*);
};
// <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD>أ<EFBFBD>Book
class Book :public Element
{
public:
Book();
Book(string name, int price);
void accept(Visitor*);
};
#endif