From 34b417f9b52336378416e32b32e7243d41348416 Mon Sep 17 00:00:00 2001 From: FunkyMonk8111 <100250024+FunkyMonk8111@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:09:32 -0500 Subject: [PATCH 1/2] Adding missing design pattern links (#34) Added the typo or missing design pattern links per issue #22 --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6039801..f82eb91 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ There are three kinds of Design Patterns: * [Adapter](/AdapterPattern) * [Bridge](/BridgePattern) +* [Builder](/BuilderPattern) +* [ChainOfResponsibility](/ChainOfResponsibilityPattern) * [Command](/CommandPattern) * [Composite](/CompositePattern) * [Decorator](/DecoratorPattern) @@ -27,11 +29,13 @@ There are three kinds of Design Patterns: * [Factory](/FactoryPattern) * [Flyweight](/FlyweightPattern) * [Iterator](/IteratorPattern) +* [Mediator](/MediatorPattern) * [Observer](/ObserverPattern) +* [Prototype](/PrototypePattern) +* [Proxy](/ProxyPattern) * [Singleton](/SingletonPattern) +* [SingletonPattern.Tests](/SingletonPattern.Tests) * [State](/StatePattern) * [Strategy](/StrategyPattern) * [Template](/TemplatePattern) * [Visitor](/VisitorPattern) -* [Mediator](/MediatorPattern) -* [Proxy](/ProxyPattern) From 3975eae85bf104af87e94efa592548a325624f83 Mon Sep 17 00:00:00 2001 From: vikramvee Date: Thu, 11 Jan 2024 03:40:17 +0530 Subject: [PATCH 2/2] Cleaned the code by removing the string literals (#33) * Removed the use of String Literals * Removed the use of String Literals for clean code --- .../Factory Method/ChicagoPizzaFactory.cs | 16 ++++++++++------ .../Factory Method/NYPizzaFactory.cs | 16 ++++++++++------ FactoryPattern/Factory Method/PizzaFactory.cs | 4 ++-- FactoryPattern/Helper.cs | 18 ++++++++++++++++++ FactoryPattern/Program.cs | 4 ++-- 5 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 FactoryPattern/Helper.cs diff --git a/FactoryPattern/Factory Method/ChicagoPizzaFactory.cs b/FactoryPattern/Factory Method/ChicagoPizzaFactory.cs index 2075587..234bdb0 100644 --- a/FactoryPattern/Factory Method/ChicagoPizzaFactory.cs +++ b/FactoryPattern/Factory Method/ChicagoPizzaFactory.cs @@ -2,25 +2,29 @@ { class ChicagoPizzaFactory : PizzaFactory { - protected override Pizza Create(string type) + private readonly string chicagoCheese = "Chicago Cheese"; + private readonly string chicagoClam = "Chicago Clam"; + private readonly string chicagoVeggie = "Chicago Veggie"; + + protected override Pizza Create(PizzaType type) { Pizza pizza; IIngredientsFactory ingredients = new ChicagoIngredientsFactory(); - if (type.Equals("Cheese")) + if (type == PizzaType.Cheese) { pizza = new CheesePizza(ingredients); - pizza.Name = "Chicago Cheese"; + pizza.Name = chicagoCheese; } - else if (type.Equals("Clam")) + else if (type == PizzaType.Clam) { pizza = new ClamPizza(ingredients); - pizza.Name = "Chicago Clam"; + pizza.Name = chicagoClam; } else { pizza = new VeggiePizza(ingredients); - pizza.Name = "Chicago Veggie"; + pizza.Name = chicagoVeggie; } pizza.Color = "red"; return pizza; diff --git a/FactoryPattern/Factory Method/NYPizzaFactory.cs b/FactoryPattern/Factory Method/NYPizzaFactory.cs index 2c24bff..de2d0b7 100644 --- a/FactoryPattern/Factory Method/NYPizzaFactory.cs +++ b/FactoryPattern/Factory Method/NYPizzaFactory.cs @@ -2,22 +2,26 @@ { class NyPizzaFactory : PizzaFactory { - protected override Pizza Create(string type) + private readonly string nyStyleCheese = "NY Style Cheese"; + private readonly string nyStyleClam = "NY Style Clam"; + private readonly string nyStyleVeggie = "NY Style Veggie"; + + protected override Pizza Create(PizzaType type) { Pizza pizza; IIngredientsFactory ingredients = new NyIngredientsFactory(); - if (type.Equals("Cheese")) + if (type == PizzaType.Cheese) { - pizza = new CheesePizza(ingredients) { Name = "NY Style Cheese" }; + pizza = new CheesePizza(ingredients) { Name = nyStyleCheese }; } - else if (type.Equals("Clam")) + else if (type == PizzaType.Clam) { - pizza = new ClamPizza(ingredients) { Name = "NY Style Clam" }; + pizza = new ClamPizza(ingredients) { Name = nyStyleClam }; } else { - pizza = new VeggiePizza(ingredients) { Name = "NY Style Veggie" }; + pizza = new VeggiePizza(ingredients) { Name = nyStyleVeggie }; } pizza.Color = "blue"; return pizza; diff --git a/FactoryPattern/Factory Method/PizzaFactory.cs b/FactoryPattern/Factory Method/PizzaFactory.cs index 31ead68..f0b7a38 100644 --- a/FactoryPattern/Factory Method/PizzaFactory.cs +++ b/FactoryPattern/Factory Method/PizzaFactory.cs @@ -2,7 +2,7 @@ { abstract class PizzaFactory { - public Pizza Order(string type) + public Pizza Order(PizzaType type) { var pizza = Create(type); pizza.Prepare(); @@ -12,6 +12,6 @@ public Pizza Order(string type) return pizza; } - protected abstract Pizza Create(string type); + protected abstract Pizza Create(PizzaType type); } } diff --git a/FactoryPattern/Helper.cs b/FactoryPattern/Helper.cs new file mode 100644 index 0000000..4a897e8 --- /dev/null +++ b/FactoryPattern/Helper.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryPattern +{ + internal class Helper + { + } + + internal enum PizzaType + { + Cheese, + Clam + } +} diff --git a/FactoryPattern/Program.cs b/FactoryPattern/Program.cs index d16bc6f..0612463 100644 --- a/FactoryPattern/Program.cs +++ b/FactoryPattern/Program.cs @@ -8,11 +8,11 @@ static void Main() { Console.WriteLine("Yankees fan orders:"); var yankees = new NyPizzaFactory(); - yankees.Order("Cheese"); + yankees.Order(PizzaType.Cheese); Console.WriteLine(); Console.WriteLine("Cubs fan orders:"); var cubs = new ChicagoPizzaFactory(); - cubs.Order("Clam"); + cubs.Order(PizzaType.Clam); } } } \ No newline at end of file