forked from yogykwan/design-patterns-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaggregate.h
More file actions
52 lines (41 loc) · 813 Bytes
/
aggregate.h
File metadata and controls
52 lines (41 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Created by Jennica on 2017/1/2.
//
#ifndef DESIGN_PATTERNS_AGGREGATE_H
#define DESIGN_PATTERNS_AGGREGATE_H
#include <vector>
class Iterator;
class Aggregate {
public:
virtual ~Aggregate() {}
virtual Iterator* CreateIterator() = 0;
};
class List: public Aggregate {
public:
Iterator* CreateIterator();
int Count();
int operator[] (int) const;
void Insert(int);
private:
std::vector <int> items_;
};
class Iterator {
public:
virtual int First() = 0;
virtual int Next() = 0;
virtual bool IsDone() = 0;
virtual int CurrentItem() = 0;
};
class ListIterator: public Iterator {
public:
ListIterator() {}
ListIterator(List*);
int First();
int Next();
bool IsDone();
int CurrentItem();
private:
int current_;
List *aggregate_;
};
#endif //DESIGN_PATTERNS_AGGREGATE_H