-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractFactory.cs
More file actions
91 lines (78 loc) · 2.07 KB
/
Copy pathAbstractFactory.cs
File metadata and controls
91 lines (78 loc) · 2.07 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
public interface INotificationFactory
{
IEmailNotification CreateEmailNotification();
ISmsNotification CreateSmsNotification();
}
public class BasicNotificationFactory : INotificationFactory
{
public IEmailNotification CreateEmailNotification()
{
return new BasicEmailNotification();
}
public ISmsNotification CreateSmsNotification()
{
return new BasicSmsNotification();
}
}
public class PremiumNotificationFactory : INotificationFactory
{
public IEmailNotification CreateEmailNotification()
{
return new PremiumEmailNotification();
}
public ISmsNotification CreateSmsNotification()
{
return new PremiumSmsNotification();
}
}
public interface IEmailNotification
{
void SendEmail(string message);
}
public interface ISmsNotification
{
void SendSms(string message);
}
public class BasicEmailNotification : IEmailNotification
{
public void SendEmail(string message)
{
Console.WriteLine("Sending basic email: " + message);
}
}
public class BasicSmsNotification : ISmsNotification
{
public void SendSms(string message)
{
Console.WriteLine("Sending basic SMS: " + message);
}
}
public class PremiumEmailNotification : IEmailNotification
{
public void SendEmail(string message)
{
Console.WriteLine("Sending premium email with extra features: " + message);
}
}
public class PremiumSmsNotification : ISmsNotification
{
public void SendSms(string message)
{
Console.WriteLine("Sending premium SMS with extra features: " + message);
}
}
public class NotificationService
{
private readonly IEmailNotification _emailNotification;
private readonly ISmsNotification _smsNotification;
public NotificationService(INotificationFactory factory)
{
_emailNotification = factory.CreateEmailNotification();
_smsNotification = factory.CreateSmsNotification();
}
public void SendNotifications(string message)
{
_emailNotification.SendEmail(message);
_smsNotification.SendSms(message);
}
}