Skip to content

Commit 1411250

Browse files
committed
chnages to visitor pattern
1 parent 4005efd commit 1411250

File tree

1 file changed

+77
-77
lines changed

1 file changed

+77
-77
lines changed

VisitorPattern/Program.cs

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,120 +2,120 @@
22

33
namespace VisitorPattern
44
{
5-
// Visitee
6-
interface IAnimal
7-
{
8-
void Accept(IAnimalOperation operation);
9-
}
10-
11-
// Visitor
12-
interface IAnimalOperation
13-
{
14-
void VisitMonkey(Monkey monkey);
15-
void VisitLion(Lion lion);
16-
void VisitDolphin(Dolphin dolphin);
17-
}
18-
19-
class Monkey : IAnimal
20-
{
21-
public void Shout()
5+
// Visitee
6+
interface IAnimal
227
{
23-
Console.WriteLine("Oooh o aa aa!");
8+
void Accept(IAnimalOperation operation);
249
}
2510

26-
public void Accept(IAnimalOperation operation)
11+
// Visitor
12+
interface IAnimalOperation
2713
{
28-
throw new NotImplementedException();
14+
void VisitMonkey(Monkey monkey);
15+
void VisitLion(Lion lion);
16+
void VisitDolphin(Dolphin dolphin);
2917
}
30-
}
3118

32-
class Lion : IAnimal
33-
{
34-
public void Roar()
19+
class Monkey : IAnimal
3520
{
36-
Console.WriteLine("Roaar!");
37-
}
21+
public void Shout()
22+
{
23+
Console.WriteLine("Oooh o aa aa!");
24+
}
3825

39-
public void Accept(IAnimalOperation operation)
40-
{
41-
throw new NotImplementedException();
26+
public void Accept(IAnimalOperation operation)
27+
{
28+
throw new NotImplementedException();
29+
}
4230
}
43-
}
4431

45-
class Dolphin : IAnimal
46-
{
47-
public void Speak()
32+
class Lion : IAnimal
4833
{
49-
Console.WriteLine("Tuut tittu tuutt!");
50-
}
34+
public void Roar()
35+
{
36+
Console.WriteLine("Roaar!");
37+
}
5138

52-
public void Accept(IAnimalOperation operation)
53-
{
54-
throw new NotImplementedException();
39+
public void Accept(IAnimalOperation operation)
40+
{
41+
throw new NotImplementedException();
42+
}
5543
}
56-
}
5744

58-
class Speak : IAnimalOperation
59-
{
60-
public void VisitDolphin(Dolphin dolphin)
45+
class Dolphin : IAnimal
6146
{
62-
dolphin.Speak();
63-
}
47+
public void Speak()
48+
{
49+
Console.WriteLine("Tuut tittu tuutt!");
50+
}
6451

65-
public void VisitLion(Lion lion)
66-
{
67-
lion.Roar();
52+
public void Accept(IAnimalOperation operation)
53+
{
54+
throw new NotImplementedException();
55+
}
6856
}
6957

70-
public void VisitMonkey(Monkey monkey)
58+
class Speak : IAnimalOperation
7159
{
72-
monkey.Shout();
73-
}
74-
}
60+
public void VisitDolphin(Dolphin dolphin)
61+
{
62+
dolphin.Speak();
63+
}
7564

76-
class Jump : IAnimalOperation
77-
{
78-
public void VisitDolphin(Dolphin dolphin)
79-
{
80-
Console.WriteLine("Jumped 20 feet high! on to the tree!");
81-
}
65+
public void VisitLion(Lion lion)
66+
{
67+
lion.Roar();
68+
}
8269

83-
public void VisitLion(Lion lion)
84-
{
85-
Console.WriteLine("Jumped 7 feet! Back on the ground!");
70+
public void VisitMonkey(Monkey monkey)
71+
{
72+
monkey.Shout();
73+
}
8674
}
8775

88-
public void VisitMonkey(Monkey monkey)
76+
class Jump : IAnimalOperation
8977
{
90-
Console.WriteLine("Walked on water a little and disappeared!");
78+
public void VisitDolphin(Dolphin dolphin)
79+
{
80+
Console.WriteLine("Walked on water a little and disappeared!");
81+
}
82+
83+
public void VisitLion(Lion lion)
84+
{
85+
Console.WriteLine("Jumped 7 feet! Back on the ground!");
86+
}
87+
88+
public void VisitMonkey(Monkey monkey)
89+
{
90+
Console.WriteLine("Jumped 20 feet high! on to the tree!");
91+
}
9192
}
92-
}
9393

9494

9595
class Program
9696
{
9797
static void Main(string[] args)
9898
{
99-
var monkey = new Monkey();
100-
var lion = new Lion();
101-
var dolphin = new Dolphin();
99+
var monkey = new Monkey();
100+
var lion = new Lion();
101+
var dolphin = new Dolphin();
102102

103-
var speak = new Speak();
103+
var speak = new Speak();
104104

105-
monkey.Accept(speak); // Ooh oo aa aa!
106-
lion.Accept(speak); // Roaaar!
107-
dolphin.Accept(speak); // Tuut tutt tuutt!
105+
monkey.Accept(speak); // Ooh oo aa aa!
106+
lion.Accept(speak); // Roaaar!
107+
dolphin.Accept(speak); // Tuut tutt tuutt!
108108

109-
var jump = new Jump();
109+
var jump = new Jump();
110110

111-
monkey.Accept(speak); // Ooh oo aa aa!
112-
monkey.Accept(jump); // Jumped 20 feet high! on to the tree!
111+
monkey.Accept(speak); // Ooh oo aa aa!
112+
monkey.Accept(jump); // Jumped 20 feet high! on to the tree!
113113

114-
lion.Accept(speak); // Roaaar!
115-
lion.Accept(jump); // Jumped 7 feet! Back on the ground!
114+
lion.Accept(speak); // Roaaar!
115+
lion.Accept(jump); // Jumped 7 feet! Back on the ground!
116116

117-
dolphin.Accept(speak); // Tuut tutt tuutt!
118-
dolphin.Accept(jump); // Walked on water a little and disappeared
117+
dolphin.Accept(speak); // Tuut tutt tuutt!
118+
dolphin.Accept(jump); // Walked on water a little and disappeared
119119

120120
Console.ReadLine();
121121
}

0 commit comments

Comments
 (0)