-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
using design_patterns.src.Singleton; | ||
using design_patterns.src.Factory; | ||
using design_patterns.src.Singleton; | ||
using design_patterns.src.Singleton.EcommerceSample; | ||
|
||
Console.WriteLine("WELCOME TO DESIGN PATTERNS IN C#!"); | ||
|
||
Console.WriteLine("\n---------------- Singleton Pattern 🚀"); | ||
SingletonUsage.SampleOne(); | ||
SingletonEcommerce.Usage(); | ||
SingletonEcommerce.Usage(); | ||
|
||
Console.WriteLine("\n---------------- Factory Pattern 🚀"); | ||
FactoryNetworkUsage.SampleOne(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using design_patterns.src.Factory.NetworkFactoryPath; | ||
|
||
namespace design_patterns.src.Factory | ||
{ | ||
/// <summary> | ||
/// Factory Pattern Network usage | ||
/// </summary> | ||
public static class FactoryNetworkUsage | ||
{ | ||
public static void SampleOne() | ||
{ | ||
Console.WriteLine("\nFactory Pattern Usage : "); | ||
NetworkFactory networkFactory = new(); | ||
var ping = networkFactory.GetNetworkInstance("ping"); | ||
var dns = networkFactory.GetNetworkInstance("dns"); | ||
var arp = networkFactory.GetNetworkInstance("arp"); | ||
|
||
ping.SendRequest("11111", 1); | ||
dns.SendRequest("22222", 2); | ||
arp.SendRequest("33333", 3); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
design-patterns/src/Factory/NetworkFactory/NetworkFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using design_patterns.src.Factory.NetworkUtility; | ||
|
||
namespace design_patterns.src.Factory.NetworkFactoryPath | ||
{ | ||
public class NetworkFactory | ||
{ | ||
/// <summary> | ||
/// Get Network Instance | ||
/// </summary> | ||
/// <param name="type"></param> | ||
/// <returns></returns> | ||
public INetwork GetNetworkInstance(string type) | ||
{ | ||
INetwork? obj = null; | ||
|
||
if (type.ToLower().Equals("ping")) | ||
{ | ||
obj = new Ping(); | ||
} | ||
else if (type.ToLower().Equals("arp")) | ||
{ | ||
obj = new ARP(); | ||
} | ||
else if (type.ToLower().Equals("dns")) | ||
{ | ||
obj = new DNS(); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Type {type} is not found"); | ||
} | ||
|
||
return obj!; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace design_patterns.src.Factory.NetworkUtility | ||
{ | ||
/// <summary> | ||
/// ARP Class | ||
/// </summary> | ||
public class ARP : INetwork | ||
{ | ||
/// <summary> | ||
/// ARP Send Request | ||
/// </summary> | ||
/// <param name="ip"></param> | ||
/// <param name="timesSent"></param> | ||
public void SendRequest(string ip, int timesSent) | ||
{ | ||
Console.WriteLine("ARP request sent to " + ip + " " + timesSent + " times"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace design_patterns.src.Factory.NetworkUtility | ||
{ | ||
/// <summary> | ||
/// DNS Class | ||
/// </summary> | ||
public class DNS : INetwork | ||
{ | ||
/// <summary> | ||
/// DNS Send Request | ||
/// </summary> | ||
/// <param name="ip"></param> | ||
/// <param name="timesSent"></param> | ||
public void SendRequest(string ip, int timesSent) | ||
{ | ||
Console.WriteLine("DNS request sent to " + ip + " " + timesSent + " times"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace design_patterns.src.Factory.NetworkUtility | ||
{ | ||
/// <summary> | ||
/// Abstracting with Network Interface | ||
/// </summary> | ||
public interface INetwork | ||
{ | ||
void SendRequest(string ip, int timesSent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace design_patterns.src.Factory.NetworkUtility | ||
{ | ||
/// <summary> | ||
/// Ping Class | ||
/// </summary> | ||
public class Ping : INetwork | ||
{ | ||
/// <summary> | ||
/// Ping Send Request | ||
/// </summary> | ||
/// <param name="ip"></param> | ||
/// <param name="timesSent"></param> | ||
public void SendRequest(string ip, int timesSent) | ||
{ | ||
Console.WriteLine("Ping request sent to " + ip + " " + timesSent + " times"); | ||
} | ||
} | ||
} |