-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcar_visitor.puml
81 lines (65 loc) · 1.71 KB
/
car_visitor.puml
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
78
79
80
81
@startuml
skinparam classAttributeIconSize 0
' Ensure vertical layout
left to right direction
interface "Interface \n CarElement" as CarElement
{
+{abstract} accept(CarElementVisitor *visitor):void
}
interface "Interface \n CarElementVisitor" as CarElementVisitor
{
+{abstract} visit(Body *body):void
+{abstract} visit(Car *car):void
+{abstract} visit(Engine *engine):void
+{abstract} visit(Wheel *wheel):void
}
CarElement <|-- Body
CarElement <|-- Wheel
CarElement <|-- Engine
CarElement <|-- Car
CarElementVisitor <|-- CarElementDoVisitor
CarElementVisitor <|-- CarElementPrintVisitor
class Wheel
{
private:
string name;
public:
+ Wheel(string name):void
+ getName():string
+ accept(CarElementVisitor *visitor):void
}
note " visitor->visit(this)" as Wheelaccept
class Body
{
+ accept(CarElementVisitor *visitor)
}
class Engine
{
accept(CarElementVisitor *visitor):void
}
class Car
{
- vector<CarElement*> elements;
+ Car()
+ accept(CarElementVisitor *visitor):void
}
note "this->elements = std::vector<CarElement*>{\n new Wheel('front left'), new Wheel('front right'),\n new Wheel('back left'), new Wheel('back right'),\n new Body(), new Engine()}" as CarConstruct
note "for (CarElement* element : elements)\n {element->accept(visitor);\n }\n visitor->visit(this);" as CarAccept
class CarElementDoVisitor
{
+ visit(Body *body):void
+ visit(Car *car):void
+ visit(Wheel *wheel):void
+ visit(Engine *engine):void
}
class CarElementPrintVisitor
{
+visit(Body *body):void
+ visit(Car *car):void
+ visit(Engine *engine):void
+ visit(Wheel *wheel):void
}
Wheelaccept -up..Wheel::accept
CarConstruct -down..Car::Car
CarAccept -up..Car::accept
@enduml