-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathProgram.cs
More file actions
162 lines (131 loc) · 6.41 KB
/
Program.cs
File metadata and controls
162 lines (131 loc) · 6.41 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Collections;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.XPath;
using DesignPatterns.Builder;
using DesignPatterns.Factory;
using DesignPatterns.Prototype;
using DesignPatterns.Singleton;
using DesignPatterns.StructuralPatterns.Adapter;
using DesignPatterns.StructuralPatterns.Facade;
using Newtonsoft.Json;
namespace DesignPatterns
{
class Program
{
static void WriteColoredLine(
string text, ConsoleColor color = ConsoleColor.Green)
{
Console.ForegroundColor =color ;
Console.WriteLine(text);
}
static void Main(string[] args)
{
#region Creational Patterns
#region singleton
/* Task task1 = Task.Factory.StartNew(() => {
Counter counter1 = Counter.GetInstance();
counter1.AddOne();
Console.WriteLine("counter 1 :"+ counter1.count.ToString());
});
Task task2 = Task.Factory.StartNew(() => {
Counter counter2 = Counter.GetInstance();
counter2.AddOne();
Console.WriteLine("counter 2 :"+ counter2.count.ToString());
Console.WriteLine();
}); */
//counter1.AddOne();
//Console.WriteLine("counter 1 :"+ counter1.count.ToString());
//Console.WriteLine("counter 2 :"+ counter2.count.ToString());
#endregion
#region prototype
/*EmployeePrototype tempEmp1 = new TempEmployee();
tempEmp1.Name = "temp employee 1";
tempEmp1.Id = 1;
tempEmp1.EmpAddress = new Address{City="city 1", Building="B1", StreetName="street name"};
EmployeePrototype tempEmp2 =tempEmp1.ShallowCopy();
Console.WriteLine("========= Temp Emp 1 Original Values=============");
Console.WriteLine(tempEmp1.ToString());
Console.WriteLine("========= Temp Emp 2 Copy========================");
Console.WriteLine(tempEmp2.ToString());
tempEmp2.EmpAddress.City="new city";
tempEmp2.Name="sadasdasd";
tempEmp2.Id=1000;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("========= Temp Emp 1 After Change =============");
Console.WriteLine(tempEmp1.ToString());
Console.WriteLine("========= Temp Emp 2 ==========================");
Console.WriteLine(tempEmp2.ToString());*/
#endregion
#region Builder
/*System.Text.StringBuilder sb =new System.Text.StringBuilder();
sb.Append("Word 1,");
sb.Append("Word 2");
WriteColoredLine(sb.ToString(),ConsoleColor.Cyan);*/
/*WriteColoredLine("***Builder Pattern***",ConsoleColor.Yellow);
Director director = new Director();
IBuilder carBuilder = new Car("Jeep");
IBuilder motorCycleBuilder = new MotorCycle("Honda");*/
// Making Car
/*director.Construct(carBuilder);
Product car = carBuilder.GetVehicle();
WriteColoredLine($"Car {car.Show()}");
//Making MotorCycle
director.Construct(motorCycleBuilder);
Product motorCycle = motorCycleBuilder.GetVehicle();
WriteColoredLine($"MotorCycle {motorCycle.Show()}");*/
#endregion
#region Factory Method
/*string cardNumber,bankCode;
BankFactory bankFactory = new BankFactory ();
WriteColoredLine("Enter your card number",ConsoleColor.Cyan);
cardNumber=Console.ReadLine();
bankCode=cardNumber.Substring(0,6);
IBank bank = bankFactory.GetBank(bankCode);
IPaymentCard paymentCard = bankFactory.GetPaymentCard("12");
WriteColoredLine(bank.Withdraw());
WriteColoredLine(paymentCard.GetName());*/
#endregion
#endregion
#region Structural Patterns
#region Proxy
/*StructuralPatterns.SMSServiceProxy proxy = new StructuralPatterns.SMSServiceProxy ();
WriteColoredLine(proxy.SendSMS("123","01100000","message 1"));
WriteColoredLine(proxy.SendSMS("123","01100000","message 1"));
WriteColoredLine(proxy.SendSMS("123","01100000","message 1"));*/
#endregion
#region Decorator
/*StructuralPatterns.ConcereteSMSService smsService = new StructuralPatterns.ConcereteSMSService ();
StructuralPatterns.NotificationEmailDecorator emailDecorator = new StructuralPatterns.NotificationEmailDecorator();
emailDecorator.SetService(smsService);
WriteColoredLine(emailDecorator.SendSMS("123","01100000","message 1"));*/
#endregion
#region Adapter
/*Employee emp =new Employee ();
MachineOperator machineOperator=new MachineOperator ();
machineOperator.BasicSalary =1200;
emp.Name ="test"; emp.BasicSalary=1000;
SalaryAdapter calculator = new SalaryAdapter ();
var salary= calculator.CalcSalary(machineOperator);
WriteColoredLine(salary.ToString());*/
#endregion
#region Facade
/* ShoppingBasket basket =new ShoppingBasket ();
basket.AddItem(new BasketItem {ItemID="123",ItemPrice=50,Quantity=3});
basket.AddItem(new BasketItem {ItemID="456",ItemPrice=40,Quantity=2});
PurchaseOrder order = new PurchaseOrder ();
order.CreateOrder(basket,"name:mohammed,bank:123456789,mobile:0100000");
*/
#endregion
#region Flyweight
DiscountCalcFactory discountFactory = new DiscountCalcFactory ();
var calculator = discountFactory.GetDiscountCalc("day");
var val=calculator.GetDiscountValue(DateTime.Now.Date);
WriteColoredLine(val.ToString());
#endregion
#endregion // End of structural patterns
Console.ReadKey();
}
}
}