-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassical.h
52 lines (42 loc) · 1.07 KB
/
classical.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
#ifndef _SHAPE_H_
#define _SHAPE_H_
namespace classical {
class Shape;
class Hexagon;
class Circle;
class Trapezium;
class Visitor {
public:
virtual float visit(Hexagon* h) = 0;
virtual float visit(Circle* c) = 0;
virtual float visit(Trapezium* t) = 0;
};
class AreaVisitor : public Visitor {
public:
float visit(Hexagon* h) { return 1; }
float visit(Circle* c) { return 2; }
float visit(Trapezium* t) { return 3; }
};
class ParimeterVisitor : public Visitor {
public:
float visit(Hexagon* h) { return 11; }
float visit(Circle* c) { return 22; }
float visit(Trapezium* t) { return 33; }
};
class Shape {
public:
virtual float Accept(Visitor* visitor) = 0;
virtual ~Shape() {}
};
class Hexagon : public Shape {
public:
float Accept(Visitor* visitor) { return visitor->visit(this); }
};
class Circle : public Shape {
float Accept(Visitor* visitor) { return visitor->visit(this); }
};
class Trapezium : public Shape {
float Accept(Visitor* visitor) { return visitor->visit(this); }
};
} // namespace classical
#endif