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

45 lines
649 B
C
Raw Normal View History

2019-11-10 14:59:08 +00:00
#ifndef __VISITOR_H__
#define __VISITOR_H__
#include <iostream>
using namespace std;
// ǰ<><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class Element;
class Apple;
class Book;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class Visitor
{
public:
Visitor(){};
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD>
virtual void visit(Apple*) = 0;
virtual void visit(Book*) = 0;
};
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><DFA3>˿<EFBFBD>
class Customer :public Visitor
{
public:
Customer();
Customer(string iName);
void setNum(Apple*, int);
void setNum(Book*, int);
void visit(Apple* apple);
void visit(Book* book);
private:
string name;
};
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD><EFBFBD><EFBFBD>Ա
class Cashier :public Visitor
{
public:
Cashier();
void visit(Apple* apple);
void visit(Book* book);
};
#endif