forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChainedIsFix2.cs
More file actions
32 lines (31 loc) · 740 Bytes
/
Copy pathChainedIsFix2.cs
File metadata and controls
32 lines (31 loc) · 740 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
class ChainedIs
{
interface Visitor
{
void Visit(Cat c);
void Visit(Dog d);
}
class SpeakVisitor : Visitor
{
public void Visit(Cat c) { Console.WriteLine("Miaow!"); }
public void Visit(Dog d) { Console.WriteLine("Woof!"); }
}
interface Animal
{
void Accept(Visitor v);
}
class Cat : Animal
{
public void Accept(Visitor v) { v.Visit(this); }
}
class Dog : Animal
{
public void Accept(Visitor v) { v.Visit(this); }
}
public static void Main(string[] args)
{
List<Animal> animals = new List<Animal> { new Cat(), new Dog() };
foreach (var a in animals)
a.Accept(new SpeakVisitor());
}
}