Skip to content

Commit ecc00c0

Browse files
Add new Example.
1 parent cfe8764 commit ecc00c0

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

Examples/E2/Notification.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
public interface INotification
2+
{
3+
void Send(string message);
4+
}
5+
6+
public class EmailNotification : INotification
7+
{
8+
public void Send(string message) => Console.WriteLine($"Email sent: {message}");
9+
}
10+
11+
public class SmsNotification : INotification
12+
{
13+
public void Send(string message) => Console.WriteLine($"SMS sent: {message}");
14+
}
15+
16+
#region Thid block of code is not in your code base, it is a library(3rd party)
17+
public class SlackNotification
18+
{
19+
public void PostMessageToChannel(string channel, string message)
20+
{
21+
Console.WriteLine($"Message sent to Slack channel {channel}: {message}");
22+
}
23+
}
24+
#endregion
25+
26+
public class NotificationService()
27+
{
28+
public ... Get(string type)
29+
{
30+
if (type == "Email")
31+
return new ...();
32+
else if (type == "SMS")
33+
return new ...();
34+
else if (type == "Slack")
35+
return new ...();
36+
37+
else
38+
throw new ArgumentException("Invalid notification type.");
39+
}
40+
}

0 commit comments

Comments
 (0)