-
Notifications
You must be signed in to change notification settings - Fork 11
/
GoF2.h
77 lines (62 loc) · 1.84 KB
/
GoF2.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once
namespace CompositePattern::GoF2
{
class Watt {};
class Currency {};
class Iterator {};
class List {};
class Equipment {
public:
virtual ~Equipment() {}
const char* Name() { return _name; }
virtual Watt Power() { return *new Watt(); }
virtual Currency NetPrice() { return *new Currency(); }
virtual Currency DiscountPrice() { return *new Currency(); }
virtual void Add(Equipment*) {}
virtual void Remove(Equipment*) {}
virtual Iterator* CreateIterator() {}
protected:
Equipment(const char*) {}
private:
const char* _name;
};
class FloppyDisk : public Equipment {
public:
FloppyDisk(const char* name) : Equipment(name) {}
virtual ~FloppyDisk() {}
virtual Watt Power() { return *new Watt(); }
virtual Currency NetPrice() { return *new Currency(); }
virtual Currency DiscountPrice() { return *new Currency(); }
};
class CompositeEquipment : public Equipment {
public:
virtual ~CompositeEquipment() {}
virtual Watt Power() { return *new Watt(); }
virtual Currency NetPrice();
virtual Currency DiscountPrice() { return *new Currency(); }
virtual void Add(Equipment*) {}
virtual void Remove(Equipment*) {}
virtual Iterator* CreateIterator() { return nullptr; }
protected:
CompositeEquipment(const char* name) : Equipment(name) {}
private:
List _equipment;
};
Currency CompositeEquipment::NetPrice() {
Iterator* i = CreateIterator();
Currency total; // = 0;
// for (i->First(); !i->IsDone(); i->Next()) {
// total += i->CurrentItem()->NetPrice();
// }
delete i;
return total;
}
class Chassis : public CompositeEquipment {
public:
Chassis(const char* name) : CompositeEquipment(name) {}
virtual ~Chassis() {}
virtual Watt Power() { return *new Watt(); }
virtual Currency NetPrice() { return *new Currency(); }
virtual Currency DiscountPrice() { return *new Currency(); }
};
}