-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
128 lines (110 loc) · 3.69 KB
/
Program.cs
File metadata and controls
128 lines (110 loc) · 3.69 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Collections.Generic;
namespace CATtask1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Do you want to send a notfication? (yes/no)");
string answer = Console.ReadLine()?.ToLower();
if (answer == "yes")
{
NotficationFactory notficationFactory = new NotficationFactory();
notficationFactory.AddChannel();
}
else
{
Console.WriteLine("Goodbye!");
}
}
}
public interface INotficationChannel
{
void Send();
}
public class Email : INotficationChannel
{
public void Send()
{
Console.WriteLine("Sending message...");
Console.WriteLine("Email sent successfully!");
}
}
public class SMS : INotficationChannel
{
public void Send()
{
Console.WriteLine("Sending message...");
Console.WriteLine("SMS sent successfully!");
}
}
public class PushNotfications : INotficationChannel
{
public void Send()
{
Console.WriteLine("Sending message...");
Console.WriteLine("Push Notification sent successfully!");
}
}
public class NotficationManager
{
private List<INotficationChannel> channels = new List<INotficationChannel>();
public void SendNotfication(INotficationChannel channel)
{
channels.Add(channel);
channel.Send();
}
public void SendAllNotfications()
{
if (channels.Count == 0)
{
Console.WriteLine("\nNo previous channels used to send notifications.");
return;
}
Console.WriteLine("\nResending through all previously used channels");
foreach (var channel in channels)
{
channel.Send();
}
}
}
public class NotficationFactory
{
private NotficationManager notficationManager = new NotficationManager();
public void AddChannel()
{
while (true)
{
Console.WriteLine("\nChoose a notfication type to send:");
Console.WriteLine("1). Email");
Console.WriteLine("2). SMS");
Console.WriteLine("3). Push Notfication");
Console.WriteLine("4). Send to all previous channels");
Console.WriteLine("5). Exit");
Console.Write("\nYour Choice: ");
string choice = Console.ReadLine();
if (choice == "5") break;
switch (choice)
{
case "1":
notficationManager.SendNotfication(new Email());
break;
case "2":
notficationManager.SendNotfication(new SMS());
break;
case "3":
notficationManager.SendNotfication(new PushNotfications());
break;
case "4":
notficationManager.SendAllNotfications();
break;
default:
Console.WriteLine("\nINVALID CHOICE! Please enter a number from 1 to 5.");
break;
}
}
Console.WriteLine("Finished Notification Process.");
}
}
}