1 //abstraction
2 public class Person
3 {
4 private IBridge _bridge;
5
6 public Person(IBridge bridge)
7 {
8 _bridge = bridge;
9 }
10
11 public virtual void ShowFirstPerson()
12 {
13 _bridge.ShowFirst();
14 }
15
16 public virtual void ShowAllPersons()
17 {
18 _bridge.ShowAll();
19 }
20 }
21
22 //bridge
23 public interface IBridge
24 {
25 void ShowFirst();
26 void ShowAll();
27 }
28
29 //new abstraction
30 public class PersonNewVersion : Person
31 {
32 public PersonNewVersion()
33 : base(new DisplayPerson())
34 {
35 }
36
37 public override void ShowAllPersons()
38 {
39 Console.WriteLine("New version of ShowAll");
40 Console.WriteLine("----------------------");
41 base.ShowAllPersons();
42 }
43 }
44
45 //bridge implementor
46 public class DisplayPerson : IBridge
47 {
48 private List<string> _personList;
49
50 public DisplayPerson()
51 {
52 _personList = new List<string>();
53 _personList.Add("Person1");
54 _personList.Add("Person2");
55 _personList.Add("Person3");
56 _personList.Add("Person4");
57 }
58
59 public void ShowFirst()
60 {
61 Console.WriteLine(_personList.First());
62 }
63
64 public void ShowAll()
65 {
66 foreach (var item in _personList)
67 {
68 Console.WriteLine(item);
69 }
70 }
71 }
72
73 public class BridgeProgram
74 {
75 public static void Main()
76 {
77 PersonNewVersion person = new PersonNewVersion();
78
79 person.ShowFirstPerson();
80 //Output : Person1
81 person.ShowAllPersons();
82 //Output : New version of ShowAll
83 //----------------------
84 //Person1
85 //Person2
86 //Person3
87 //Person4
88 Console.ReadLine();
89 }
90 }