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

57 lines
808 B
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef __ELEMENT_H__
#define __ELEMENT_H__
#include "Visitor.h"
#include <iostream>
using namespace std;
// 抽象元素
class Element
{
public:
Element(){};
virtual ~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;
};
// 具体元素Apple
class Apple :public Element
{
public:
Apple();
Apple(string name, int price);
void accept(Visitor*);
};
// 具体元素Book
class Book :public Element
{
public:
Book();
Book(string name, int price);
void accept(Visitor*);
};
#endif