-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainApp.cs
76 lines (60 loc) · 2.35 KB
/
MainApp.cs
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
using System;
using System.Collections.Generic;
namespace DoFactory.GangOfFour.Mediator.RealWorld
{
/// <summary>
/// MainApp startup class for Real-World
/// Mediator Design Pattern.
/// </summary>
class MainApp
{
/// <summary>
/// Entry point into console application.
/// </summary>
static void Main()
{
// Create chatroom
Chatroom chatroom = new Chatroom();
List<Participant> beatle = new List<Participant>();
List<Participant> nonBeatle = new List<Participant>();
//Message for everyone
String firstMessage = "Hello there!";
String secondMessage = "Hello Beatles!";
String thirdMessage = "Hello non Beatles!";
// Create participants and register them
Participant George = new Beatle("George");
Participant Paul = new Beatle("Paul");
Participant Ringo = new Beatle("Ringo");
Participant John = new Beatle("John");
Participant Yoko = new NonBeatle("Yoko");
Participant Mark = new NonBeatle("Mark");
chatroom.Register(George);
chatroom.Register(Paul);
chatroom.Register(Ringo);
chatroom.Register(John);
chatroom.Register(Yoko);
chatroom.Register(Mark);
//Add participants to groups
beatle.Add(George);
beatle.Add(Paul);
beatle.Add(Ringo);
beatle.Add(John);
nonBeatle.Add(Yoko);
nonBeatle.Add(Mark);
// Chatting participants
Yoko.Send("John", "Hi John!");
Paul.Send("Ringo", "All you need is love");
Ringo.Send("George", "My sweet Lord");
Paul.Send("John", "Can't buy me love");
John.Send("Yoko", "My sweet love");
Console.WriteLine("\nJohn is sending Hello there! to everyone in the chatroom\n");
John.SendAll(firstMessage);
Console.WriteLine("\nSending a meassge to the Beatles group\n");
Yoko.SendMany(beatle, secondMessage);
Console.WriteLine("\nSending a meassge to the non Beatles group\n");
Ringo.SendMany(nonBeatle, thirdMessage);
// Wait for user
Console.ReadKey();
}
}
}