DesignPattern/17.IteratorPattern/2.Code/Aggregate.h

36 lines
668 B
C
Raw Normal View History

2019-11-03 06:20:17 +00:00
#ifndef __AGGREGATE_H__
#define __AGGREGATE_H__
#include <vector>
2021-10-28 15:15:51 +00:00
#include <string>
2019-11-03 06:20:17 +00:00
using namespace std;
2021-10-28 15:15:51 +00:00
// 前向声明,因为两个类互相引用
2019-11-03 06:20:17 +00:00
class Iterator;
class RemoteControl;
2021-10-28 15:15:51 +00:00
// 抽象聚合类 Aggregate
2019-11-03 06:20:17 +00:00
class Aggregate
{
public:
Aggregate(){}
virtual ~Aggregate(){}
2019-11-03 06:20:17 +00:00
virtual Iterator* createIterator() = 0;
};
2021-10-28 15:15:51 +00:00
// 具体聚合类 Television
2019-11-03 06:20:17 +00:00
class Television :public Aggregate
{
public:
Television();
2021-10-28 15:15:51 +00:00
Television(vector<std::string> iChannelList);
// 实现创建迭代器
2019-11-03 06:20:17 +00:00
Iterator* createIterator();
2021-10-28 15:15:51 +00:00
// 获取总的频道数目
2019-11-03 06:20:17 +00:00
int getTotalChannelNum();
void play(int i);
private:
2021-10-28 15:15:51 +00:00
vector<std::string> channelList;
2019-11-03 06:20:17 +00:00
};
#endif //__AGGREGATE_H__