├── .gitattributes ├── .gitignore ├── A-OO In Reality ├── A Encapsulation 1 │ ├── A Encapsulation 1.csproj │ ├── App.config │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── A Encapsulation 2 │ ├── A Encapsulation 2.csproj │ ├── App.config │ ├── CoffeeRecipe.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Recipe.cs │ └── TeaRecipe.cs ├── A Extensibility │ ├── A Extensibility.csproj │ ├── App.config │ ├── IStack.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Stack.cs ├── A-OO In Reality.sln └── A-OO In Reality │ ├── A-OO In Reality.csproj │ ├── App.config │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── B-Template Pattern ├── B Solution 1 │ ├── App.config │ ├── B Solution 1.csproj │ ├── CoffeeRecipe.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── TeaRecipe.cs ├── B Solution 2 │ ├── App.config │ ├── B Solution 2.csproj │ ├── CoffeeRecipe.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Recipe.cs │ └── TeaRecipe.cs ├── B Solution 3 │ ├── App.config │ ├── B Solution 3.csproj │ ├── CoffeeRecipe.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Recipe.cs │ └── TeaRecipe.cs ├── B Solution 4 │ ├── App.config │ ├── B Solution 4.csproj │ ├── CoffeeRecipe.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Recipe.cs │ └── TeaRecipe.cs ├── B-Template Pattern.sln └── B-Template Pattern │ ├── App.config │ ├── B-Template Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── C-State Pattern ├── C Solution 1 │ ├── App.config │ ├── C Solution 1.csproj │ ├── GumballMachine.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── C Solution 2 │ ├── App.config │ ├── C Solution 2.csproj │ ├── GumballMachine.cs │ ├── GumballsCoin.cs │ ├── GumballsNoCoin.cs │ ├── IState.cs │ ├── NoGumballsCoin.cs │ ├── NoGumballsNoCoin.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── C Solution 3 │ ├── App.config │ ├── C Solution 3.csproj │ ├── GumballMachine.cs │ ├── GumballsCoin.cs │ ├── GumballsNoCoin.cs │ ├── IState.cs │ ├── NoGumballsCoin.cs │ ├── NoGumballsNoCoin.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── C-State Pattern.sln └── C-State Pattern │ ├── App.config │ ├── C-State Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── D-Strategy Pattern ├── D Solution 1 │ ├── App.config │ ├── D Solution 1.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Sorter.cs ├── D Solution 2 │ ├── App.config │ ├── BubbleSorter.cs │ ├── D Solution 2.csproj │ ├── MergeSorter.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── QuickSorter.cs │ └── Sorter.cs ├── D Solution 3 │ ├── App.config │ ├── AscBubbleSorter.cs │ ├── AscMergeSorter.cs │ ├── D Solution 3.csproj │ ├── DescBubbleSorter.cs │ ├── DescMergeSorter.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Sorter.cs ├── D Solution 4 │ ├── App.config │ ├── BubbleSortAlgorithm.cs │ ├── D Solution 4.csproj │ ├── ISortAlgorithm.cs │ ├── MergeSortAlgorithm.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Sorter.cs ├── D Solution 5 │ ├── App.config │ ├── AscComparator.cs │ ├── BubbleSortAlgorithm.cs │ ├── D Solution 5.csproj │ ├── IComparator.cs │ ├── ISortAlgorithm.cs │ ├── MergeSortAlgorithm.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Sorter.cs ├── D-Strategy Pattern.sln └── D-Strategy Pattern │ ├── App.config │ ├── D-Strategy Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── Design-Patterns.sln ├── E-Observer Pattern ├── E Solution 1 │ ├── App.config │ ├── CurrentCondtionsDisplay.cs │ ├── E Solution 1.csproj │ ├── ForecastDisplay.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── StatisticsDisplay.cs │ ├── Weather.cs │ └── WeatherStation.cs ├── E Solution 2 │ ├── App.config │ ├── CurrentConditionsDisplay.cs │ ├── E Solution 2.csproj │ ├── ForecastDisplay.cs │ ├── IDisplay.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── StatisticsDisplay.cs │ ├── Weather.cs │ └── WeatherStation.cs ├── E-Observer Pattern.sln └── E-Observer Pattern │ ├── App.config │ ├── E-Observer Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── F-Mediator Pattern ├── F Solution 1 │ ├── App.config │ ├── CEditBox.cs │ ├── CLowerButton.cs │ ├── CRaiseButton.cs │ ├── F Solution 1.csproj │ ├── FEditBox.cs │ ├── FLowerButton.cs │ ├── FRaiseButton.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── TempBar.cs │ └── Utils.cs ├── F Solution 2 │ ├── App.config │ ├── CEditBox.cs │ ├── CLowerButton.cs │ ├── CRaiseButton.cs │ ├── F Solution 2.csproj │ ├── FEditBox.cs │ ├── FLowerButton.cs │ ├── FRaiseButton.cs │ ├── IButton.cs │ ├── IEditBox.cs │ ├── IMediator.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── TempBar.cs │ ├── TempDialogMediator.cs │ └── Utils.cs ├── F Solution 3 │ ├── App.config │ ├── CEditBox.cs │ ├── CLowerButton.cs │ ├── CRaiseButton.cs │ ├── F Solution 3.csproj │ ├── FEditBox.cs │ ├── FLowerButton.cs │ ├── FRaiseButton.cs │ ├── IMediator.cs │ ├── IWidget.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── TempBar.cs │ ├── TempDialogMediator.cs │ └── Utils.cs ├── F-Mediator Pattern.sln └── F-Mediator Pattern │ ├── App.config │ ├── F-Mediator Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── G-Decorator Pattern ├── G-Decorator Pattern.sln └── G-Decorator Pattern │ ├── App.config │ ├── G-Decorator Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── H-Command Pattern ├── H Solution 1 │ ├── App.config │ ├── H Solution 1.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Square.cs ├── H Solution 2 │ ├── AbstractCommand.cs │ ├── App.config │ ├── H Solution 2.csproj │ ├── Invoker.cs │ ├── MoveCommand.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ScaleCommand.cs │ └── Square.cs ├── H Solution 3 │ ├── AbstractCommand.cs │ ├── App.config │ ├── H Solution 3.csproj │ ├── Invoker.cs │ ├── MoveCommand.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ScaleCommand.cs │ └── Square.cs ├── H Solution 4 │ ├── AbstractCommand.cs │ ├── App.config │ ├── H Solution 4.csproj │ ├── Invoker.cs │ ├── MoveCommand.cs │ ├── PrintCommand.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ScaleCommand.cs │ └── Square.cs ├── H Solution 5 │ ├── AbstractCommand.cs │ ├── App.config │ ├── H Solution 5.csproj │ ├── Invoker.cs │ ├── MoveCommand.cs │ ├── PrintCommand.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ScaleCommand.cs │ └── Square.cs ├── H-Command Pattern.sln └── H-Command Pattern │ ├── App.config │ ├── H-Command Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── I-Iterator Pattern ├── I Solution 1 │ ├── App.config │ ├── BreakfastUnit.cs │ ├── DinnerUnit.cs │ ├── I Solution 1.csproj │ ├── MenuItem.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── I Solution 2 │ ├── App.config │ ├── BreakfastUnit.cs │ ├── DinnerUnit.cs │ ├── I Solution 2.csproj │ ├── Iterator.cs │ ├── MenuItem.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── I Solution 3 │ ├── App.config │ ├── BreakfastUnit.cs │ ├── BreakfastUnitIterator.cs │ ├── DinnerUnit.cs │ ├── DinnerUnitIterator.cs │ ├── I Solution 3.csproj │ ├── Iterator.cs │ ├── MenuItem.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── I-Iterator Pattern.sln └── I-Iterator Pattern │ ├── App.config │ ├── I-Iterator Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── J-Adapter Pattern ├── J Solution 1 │ ├── App.config │ ├── IStack.cs │ ├── J Solution 1.csproj │ ├── LinkedStack.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── J Solution 2 │ ├── App.config │ ├── IStack.cs │ ├── J Solution 2.csproj │ ├── LinkedStack.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── J-Adapter Pattern.sln └── J-Adapter Pattern │ ├── App.config │ ├── J-Adapter Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── K-Singleton Pattern ├── K JonSkeet 1 │ ├── App.config │ ├── K JonSkeet 1.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Singleton.cs ├── K JonSkeet 2 │ ├── App.config │ ├── K JonSkeet 2.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Singleton.cs ├── K JonSkeet 3 │ ├── App.config │ ├── K JonSkeet 3.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Singleton.cs ├── K JonSkeet 4 │ ├── App.config │ ├── K JonSkeet 4.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Singleton.cs ├── K JonSkeet 5 │ ├── App.config │ ├── K JonSkeet 5.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Singleton.cs ├── K JonSkeet 6 │ ├── App.config │ ├── K JonSkeet 6.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Singleton.cs ├── K Solution 1 │ ├── Account.cs │ ├── App.config │ ├── Bank.cs │ ├── K Solution 1.csproj │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── K-Singleton Pattern.sln └── K-Singleton Pattern │ ├── App.config │ ├── K-Singleton Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── L-Factory Method Pattern ├── L Solution 1 │ ├── App.config │ ├── CacheFactory.cs │ ├── DefaultCache.cs │ ├── ICache.cs │ ├── JCache.cs │ ├── L Solution 1.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── TrieCache.cs ├── L Solution 2 │ ├── App.config │ ├── CacheFactory.cs │ ├── DefaultCache.cs │ ├── ICache.cs │ ├── ICacheFactory.cs │ ├── JCache.cs │ ├── L Solution 2.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── TrieCache.cs ├── L-Factory Method Pattern.sln └── L-Factory Method Pattern │ ├── App.config │ ├── L-Factory Method Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── LICENSE ├── M-AbstractFactory And Builder Pattern ├── M Solution 1 │ ├── App.config │ ├── AudiCar.cs │ ├── EGearBox.cs │ ├── EStereo.cs │ ├── EWheel.cs │ ├── IGearBox.cs │ ├── IStereo.cs │ ├── IWheel.cs │ ├── LGearBox.cs │ ├── LStereo.cs │ ├── LWheel.cs │ ├── M Solution 1.csproj │ ├── MGearBox.cs │ ├── MStereo.cs │ ├── MWheel.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── M Solution 2 │ ├── App.config │ ├── AudiCar.cs │ ├── EGearBox.cs │ ├── EStereo.cs │ ├── EWheel.cs │ ├── EconomyAudiBuilder.cs │ ├── IGearBox.cs │ ├── IStereo.cs │ ├── IWheel.cs │ ├── LGearBox.cs │ ├── LStereo.cs │ ├── LWheel.cs │ ├── LuxuryAudiBuilder.cs │ ├── M Solution 2.csproj │ ├── MGearBox.cs │ ├── MStereo.cs │ ├── MWheel.cs │ ├── MediumAudiBuilder.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── M Solution 3 │ ├── AbstractAudiBuilder.cs │ ├── App.config │ ├── AudiCar.cs │ ├── EGearBox.cs │ ├── EStereo.cs │ ├── EWheel.cs │ ├── EconomyAudiBuilder.cs │ ├── IGearBox.cs │ ├── IStereo.cs │ ├── IWheel.cs │ ├── LGearBox.cs │ ├── LStereo.cs │ ├── LWheel.cs │ ├── LuxuryAudiBuilder.cs │ ├── M Solution 3.csproj │ ├── MGearBox.cs │ ├── MStereo.cs │ ├── MWheel.cs │ ├── MediumAudiBuilder.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── M Solution 4 │ ├── App.config │ ├── AudiCar.cs │ ├── EGearBox.cs │ ├── EStereo.cs │ ├── EWheel.cs │ ├── EconomyCarFactory.cs │ ├── ICarFactory.cs │ ├── IGearBox.cs │ ├── IStereo.cs │ ├── IWheel.cs │ ├── LGearBox.cs │ ├── LStereo.cs │ ├── LWheel.cs │ ├── LuxuryCarFactory.cs │ ├── M Solution 4.csproj │ ├── MGearBox.cs │ ├── MStereo.cs │ ├── MWheel.cs │ ├── MediumCarFactory.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── M-AbstractFactory And Builder Pattern.sln └── M-AbstractFactory And Builder Pattern │ ├── App.config │ ├── M-AbstractFactory And Builder Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── N-Composite Pattern ├── N Solution 1 │ ├── App.config │ ├── Directory.cs │ ├── File.cs │ ├── N Solution 1.csproj │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── N Solution 2 │ ├── App.config │ ├── Directory.cs │ ├── File.cs │ ├── N Solution 2.csproj │ ├── Node.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── N-Composite Pattern.sln └── N-Composite Pattern │ ├── App.config │ ├── N-Composite Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── O-Chain Of Responsibility Pattern ├── O Solution 1 │ ├── AbstractHandler.cs │ ├── App.config │ ├── CEO.cs │ ├── Director.cs │ ├── ExecutiveCommittee.cs │ ├── O Solution 1.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── PurchaseOrder.cs │ ├── SeniorManager.cs │ └── VP.cs ├── O-Chain Of Responsibility Pattern.sln └── O-Chain Of Responsibility Pattern │ ├── App.config │ ├── O-Chain Of Responsibility Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── P-Bridge Pattern ├── P Solution 1 │ ├── App.config │ ├── BulletView.cs │ ├── DueDateBasedSortStrategy.cs │ ├── ISortStrategy.cs │ ├── IViewStrategy.cs │ ├── ListView.cs │ ├── NumberedView.cs │ ├── P Solution 1.csproj │ ├── PriorityBasedSortStratrgy.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Task.cs │ ├── ToDoList.cs │ └── UnsortedStrategy.cs ├── P Solution 2 │ ├── AbstractView.cs │ ├── App.config │ ├── BulletView.cs │ ├── DueDateBasedSortStrategy.cs │ ├── ISortStrategy.cs │ ├── IViewStrategy.cs │ ├── ListView.cs │ ├── NumberedView.cs │ ├── P Solution 2.csproj │ ├── PriorityBasedSortStrategy.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Task.cs │ └── UnsortedStrategy.cs ├── P-Bridge Pattern.sln └── P-Bridge Pattern │ ├── App.config │ ├── P-Bridge Pattern.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── Patterns ├── App.config ├── Patterns.csproj ├── Program.cs └── Properties │ └── AssemblyInfo.cs ├── Q-Facade Pattern ├── Q Solution 1 │ ├── Address.cs │ ├── App.config │ ├── DBInventoryService.cs │ ├── DesktopController.cs │ ├── FedExShippingService.cs │ ├── ICICIPaymentService.cs │ ├── IInventoryService.cs │ ├── IPaymentService.cs │ ├── IShippingService.cs │ ├── MobileController.cs │ ├── PayPalPaymentService.cs │ ├── Product.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Q Solution 1.csproj ├── Q Solution 2 │ ├── Address.cs │ ├── App.config │ ├── DBInventoryService.cs │ ├── DesktopController.cs │ ├── FedExShippingService.cs │ ├── ICICIPaymentService.cs │ ├── IInventoryService.cs │ ├── IOrderFacade.cs │ ├── IPaymentService.cs │ ├── IShippingService.cs │ ├── MobileController.cs │ ├── OrderFacade.cs │ ├── PayPalPaymentService.cs │ ├── Product.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Q Solution 2.csproj ├── Q-Facade Pattern.sln └── Q-Facade Pattern │ ├── App.config │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── Q-Facade Pattern.csproj ├── R-Proxy Pattern ├── R Solution 1 │ ├── App.config │ ├── Document.cs │ ├── MyImage.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── R Solution 1.csproj ├── R Solution 2 │ ├── App.config │ ├── Document.cs │ ├── IProxy.cs │ ├── MyImage.cs │ ├── MyImageProxy.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── R Solution 2.csproj ├── R-Proxy Pattern.sln └── R-Proxy Pattern │ ├── App.config │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── R-Proxy Pattern.csproj ├── README.md └── _config.yml /A-OO In Reality/A Encapsulation 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /A-OO In Reality/A Encapsulation 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /A-OO In Reality/A Encapsulation 2/CoffeeRecipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace A_Encapsulation_2 8 | { 9 | public class CoffeeRecipe : Recipe 10 | { 11 | protected override void addIngradients() 12 | { 13 | Console.WriteLine("Add Milk & Sugar"); 14 | } 15 | 16 | protected override void addPowder() 17 | { 18 | Console.WriteLine("Add Coffee Powder"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /A-OO In Reality/A Encapsulation 2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace A_Encapsulation_2 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | TeaRecipe tr1 = new TeaRecipe(); 14 | tr1.makeRecipe(); 15 | 16 | Console.WriteLine(); 17 | 18 | CoffeeRecipe cr1 = new CoffeeRecipe(); 19 | cr1.makeRecipe(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /A-OO In Reality/A Encapsulation 2/Recipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace A_Encapsulation_2 4 | { 5 | //encapsulation at method impletation 6 | public abstract class Recipe 7 | { 8 | protected void boilWater() 9 | { 10 | Console.WriteLine("Boiling Water"); 11 | } 12 | protected void pour() 13 | { 14 | Console.WriteLine("Pouring into cup"); 15 | } 16 | 17 | //encapsulate the method implementations that coud vary among child objects 18 | protected abstract void addPowder(); 19 | protected abstract void addIngradients(); 20 | public void makeRecipe() 21 | { 22 | boilWater(); 23 | addPowder(); 24 | pour(); 25 | addIngradients(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /A-OO In Reality/A Encapsulation 2/TeaRecipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace A_Encapsulation_2 8 | { 9 | public class TeaRecipe : Recipe 10 | { 11 | protected override void addIngradients() 12 | { 13 | Console.WriteLine("Adding Lemon"); 14 | } 15 | 16 | protected override void addPowder() 17 | { 18 | Console.WriteLine("Adding Tea Powder"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /A-OO In Reality/A Extensibility/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /A-OO In Reality/A Extensibility/IStack.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace A_Extensibility 8 | { 9 | public interface IStack 10 | { 11 | void push(int x); 12 | int pop(); 13 | } 14 | 15 | /* class IStack { 16 | * virtual void push(Integer x)=0; 17 | * virtual Integer pop()=0; 18 | * } 19 | */ 20 | } 21 | -------------------------------------------------------------------------------- /A-OO In Reality/A Extensibility/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace A_Extensibility 8 | { 9 | class Program 10 | { 11 | // since stack implementations could change, we are hiding all the stack implementations behind IStack interface 12 | // class level encapsulation 13 | // the ideas in 00-paradigm that supports calss level encapsulation are: inheritance, polymorphism, dynamics binding 14 | public static void testStack(IStack stack) 15 | { 16 | stack.push(10); 17 | stack.push(20); 18 | Console.WriteLine(stack.pop()); 19 | } 20 | 21 | static void Main(string[] args) 22 | { 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /A-OO In Reality/A Extensibility/Stack.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace A_Extensibility 8 | { 9 | class Stack : IStack 10 | { 11 | int IStack.pop() 12 | { 13 | throw new NotImplementedException(); 14 | } 15 | 16 | void IStack.push(int x) 17 | { 18 | throw new NotImplementedException(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /A-OO In Reality/A-OO In Reality/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /A-OO In Reality/A-OO In Reality/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace A_OO_In_Reality 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 1/CoffeeRecipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace B_Solution_1 8 | { 9 | public class CoffeeRecipe 10 | { 11 | private void boilWater() 12 | { 13 | Console.WriteLine("Boiling water"); 14 | } 15 | private void addCoffeePowder() 16 | { 17 | Console.WriteLine("Adding coffee powder"); 18 | } 19 | private void pour() 20 | { 21 | Console.WriteLine("Pouring into cup"); 22 | } 23 | private void addIngradients() 24 | { 25 | Console.WriteLine("Add milk and sugar"); 26 | } 27 | 28 | public void makeCoffee() 29 | { 30 | boilWater(); 31 | addCoffeePowder(); 32 | pour(); 33 | addIngradients(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace B_Solution_1 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | TeaRecipe tr1 = new TeaRecipe(); 14 | tr1.makeTea(); 15 | 16 | Console.WriteLine(); 17 | 18 | CoffeeRecipe cr1 = new CoffeeRecipe(); 19 | cr1.makeCoffee(); 20 | } 21 | } 22 | } 23 | 24 | /* Issues: 25 | 1) code redundancy 26 | 27 | */ -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 1/TeaRecipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace B_Solution_1 8 | { 9 | public class TeaRecipe 10 | { 11 | private void boilWater() 12 | { 13 | Console.WriteLine("Boiling water"); 14 | } 15 | private void addTeaPowder() 16 | { 17 | Console.WriteLine("Adding tea powder"); 18 | } 19 | private void pour() 20 | { 21 | Console.WriteLine("Pouring into cup"); 22 | } 23 | private void addIngradients() 24 | { 25 | Console.WriteLine("Add lemon"); 26 | } 27 | 28 | public void makeTea() 29 | { 30 | boilWater(); 31 | addTeaPowder(); 32 | pour(); 33 | addIngradients(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 2/CoffeeRecipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace B_Solution_2 8 | { 9 | public class CoffeeRecipe : Recipe 10 | { 11 | private void addCoffeePowder() 12 | { 13 | Console.WriteLine("Adding coffee powder"); 14 | } 15 | private void addIngradients() 16 | { 17 | Console.WriteLine("Add milk and sugar"); 18 | } 19 | public void makeCoffee() 20 | { 21 | boilWater(); 22 | addCoffeePowder(); 23 | pour(); 24 | addIngradients(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace B_Solution_2 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | TeaRecipe tr1 = new TeaRecipe(); 14 | tr1.makeTea(); 15 | 16 | Console.WriteLine(); 17 | 18 | CoffeeRecipe cr1 = new CoffeeRecipe(); 19 | cr1.makeCoffee(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 2/Recipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace B_Solution_2 4 | { 5 | public abstract class Recipe 6 | { 7 | protected void boilWater() 8 | { 9 | Console.WriteLine("Boiling Water"); 10 | } 11 | protected void pour() 12 | { 13 | Console.WriteLine("Pouring into Cup"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 2/TeaRecipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace B_Solution_2 8 | { 9 | public class TeaRecipe : Recipe 10 | { 11 | private void addTeaPowder() 12 | { 13 | Console.WriteLine("Adding tea powder"); 14 | } 15 | private void addIngradients() 16 | { 17 | Console.WriteLine("Add lemon"); 18 | } 19 | 20 | public void makeTea() 21 | { 22 | boilWater(); 23 | addTeaPowder(); 24 | pour(); 25 | addIngradients(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 3/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 3/CoffeeRecipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace B_Solution_3 8 | { 9 | public class CoffeeRecipe : Recipe 10 | { 11 | protected override void addPowder() 12 | { 13 | Console.WriteLine("Adding coffee powder"); 14 | } 15 | protected override void addIngradients() 16 | { 17 | Console.WriteLine("Add milk and sugar"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 3/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace B_Solution_3 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | TeaRecipe tr1 = new TeaRecipe(); 10 | tr1.makeRecipe(); 11 | 12 | Console.WriteLine(); 13 | 14 | CoffeeRecipe cr1 = new CoffeeRecipe(); 15 | cr1.makeRecipe(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 3/Recipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace B_Solution_3 4 | { 5 | public abstract class Recipe 6 | { 7 | protected void boilWater() 8 | { 9 | Console.WriteLine("Boiling water"); 10 | } 11 | 12 | protected void pour() 13 | { 14 | Console.WriteLine("Pouring into cup"); 15 | } 16 | protected abstract void addPowder(); 17 | protected abstract void addIngradients(); 18 | public void makeRecipe() 19 | { 20 | boilWater(); 21 | addPowder(); 22 | pour(); 23 | addIngradients(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 3/TeaRecipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace B_Solution_3 8 | { 9 | public class TeaRecipe : Recipe 10 | { 11 | protected override void addPowder() 12 | { 13 | Console.WriteLine("Adding tea powder"); 14 | } 15 | protected override void addIngradients() 16 | { 17 | Console.WriteLine("Add lemon"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 4/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 4/CoffeeRecipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace B_Solution_4 4 | { 5 | public class CoffeeRecipe : Recipe 6 | { 7 | public CoffeeRecipe(bool needIngradients) : 8 | base(needIngradients) 9 | { 10 | } 11 | 12 | protected override void addPowder() 13 | { 14 | Console.WriteLine("Adding coffee powder"); 15 | } 16 | protected override void addIngradients() 17 | { 18 | Console.WriteLine("Add milk and sugar"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 4/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace B_Solution_4 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | TeaRecipe tr1 = new TeaRecipe(true); 10 | tr1.makeRecipe(); 11 | Console.WriteLine(); 12 | TeaRecipe tr2 = new TeaRecipe(false); 13 | tr2.makeRecipe(); 14 | Console.WriteLine(); 15 | CoffeeRecipe cr1 = new CoffeeRecipe(false); 16 | cr1.makeRecipe(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 4/Recipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace B_Solution_4 4 | { 5 | public abstract class Recipe 6 | { 7 | private bool needIngradients; 8 | 9 | public Recipe(bool needIngradients) 10 | { 11 | this.needIngradients = needIngradients; 12 | } 13 | 14 | protected void boilWater() 15 | { 16 | Console.WriteLine("Boiling water"); 17 | } 18 | 19 | protected void pour() 20 | { 21 | Console.WriteLine("Pouring into cup"); 22 | } 23 | protected abstract void addPowder(); 24 | protected abstract void addIngradients(); 25 | public void makeRecipe() 26 | { 27 | boilWater(); 28 | addPowder(); 29 | pour(); 30 | if (needIngradients) 31 | addIngradients(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /B-Template Pattern/B Solution 4/TeaRecipe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace B_Solution_4 4 | { 5 | public class TeaRecipe : Recipe 6 | { 7 | public TeaRecipe(bool needIngradients) : base(needIngradients) 8 | { 9 | } 10 | 11 | protected override void addPowder() 12 | { 13 | Console.WriteLine("Adding tea powder"); 14 | } 15 | protected override void addIngradients() 16 | { 17 | Console.WriteLine("Add lemon"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /B-Template Pattern/B-Template Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /B-Template Pattern/B-Template Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace B_Template_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /C-State Pattern/C Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /C-State Pattern/C Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace C_Solution_1 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | GumballMachine m1 = new GumballMachine(); 14 | m1.turnHandle(); 15 | Console.WriteLine(m1); 16 | m1.addGumballs(10); 17 | Console.WriteLine(m1); 18 | m1.turnHandle(); 19 | Console.WriteLine(m1); 20 | m1.insertCoin(); 21 | Console.WriteLine(m1); 22 | m1.turnHandle(); 23 | Console.WriteLine(m1); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /C-State Pattern/C Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /C-State Pattern/C Solution 2/GumballsCoin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace C_Solution_2 8 | { 9 | public class GumballsCoin : IState 10 | { 11 | private GumballMachine gbm; 12 | public GumballsCoin(GumballMachine gbm) 13 | { 14 | this.gbm = gbm; 15 | } 16 | public void addGumballs(int count) 17 | { 18 | Console.WriteLine("Added gumballs"); 19 | gbm.addCount(count); 20 | } 21 | 22 | public void insertCoin() 23 | { 24 | Console.WriteLine("Coin already inserted"); 25 | } 26 | 27 | public void turnHandle() 28 | { 29 | gbm.updateState(); 30 | if (gbm.getNumGumballs() == 0) 31 | gbm.setState(gbm.getState("ng_nc")); 32 | else 33 | gbm.setState(gbm.getState("g_nc")); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /C-State Pattern/C Solution 2/GumballsNoCoin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace C_Solution_2 8 | { 9 | public class GumballsNoCoin : IState 10 | { 11 | private GumballMachine gbm; 12 | public GumballsNoCoin(GumballMachine gbm) 13 | { 14 | this.gbm = gbm; 15 | } 16 | public void addGumballs(int count) 17 | { 18 | throw new NotImplementedException(); 19 | } 20 | 21 | public void insertCoin() 22 | { 23 | throw new NotImplementedException(); 24 | } 25 | 26 | public void turnHandle() 27 | { 28 | throw new NotImplementedException(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /C-State Pattern/C Solution 2/IState.cs: -------------------------------------------------------------------------------- 1 | namespace C_Solution_2 2 | { 3 | public interface IState 4 | { 5 | void addGumballs(int count); 6 | void insertCoin(); 7 | void turnHandle(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /C-State Pattern/C Solution 2/NoGumballsCoin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace C_Solution_2 8 | { 9 | public class NoGumballsCoin : IState 10 | { 11 | private GumballMachine gbm; 12 | public NoGumballsCoin(GumballMachine gbm) 13 | { 14 | this.gbm = gbm; 15 | } 16 | public void addGumballs(int count) 17 | { 18 | throw new NotImplementedException(); 19 | } 20 | 21 | public void insertCoin() 22 | { 23 | throw new NotImplementedException(); 24 | } 25 | 26 | public void turnHandle() 27 | { 28 | throw new NotImplementedException(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /C-State Pattern/C Solution 2/NoGumballsNoCoin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace C_Solution_2 4 | { 5 | public class NoGumballsNoCoin : IState 6 | { 7 | private GumballMachine gbm; 8 | public NoGumballsNoCoin(GumballMachine gbm) 9 | { 10 | this.gbm = gbm; 11 | } 12 | 13 | public void addGumballs(int count) 14 | { 15 | Console.WriteLine("Added Gumballs"); 16 | gbm.addCount(count); 17 | gbm.setState(gbm.getState("g_nc")); 18 | } 19 | 20 | public void insertCoin() 21 | { 22 | Console.WriteLine("Coin is Inserted"); 23 | gbm.setState(gbm.getState("ng_c")); 24 | } 25 | 26 | public void turnHandle() 27 | { 28 | Console.WriteLine("Insert Coin"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /C-State Pattern/C Solution 2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace C_Solution_2 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | GumballMachine m1 = new GumballMachine(); 14 | m1.turnHandle(); 15 | Console.WriteLine(m1); 16 | m1.addGumballs(10); 17 | Console.WriteLine(m1); 18 | m1.turnHandle(); 19 | Console.WriteLine(m1); 20 | m1.insertCoin(); 21 | Console.WriteLine(m1); 22 | m1.turnHandle(); 23 | Console.WriteLine(m1); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /C-State Pattern/C Solution 3/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /C-State Pattern/C Solution 3/GumballsNoCoin.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace C_Solution_3 4 | { 5 | public class GumballsNoCoin : IState 6 | { 7 | private static GumballsNoCoin instance = new GumballsNoCoin(); 8 | 9 | public static GumballsNoCoin getInstance 10 | { 11 | get { return instance; } 12 | } 13 | 14 | public void addGumballs(GumballMachine gbm, int count) 15 | { 16 | } 17 | 18 | public void insertCoin(GumballMachine gbm) 19 | { 20 | } 21 | 22 | public void turnHandle(GumballMachine gbm) 23 | { 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /C-State Pattern/C Solution 3/IState.cs: -------------------------------------------------------------------------------- 1 | namespace C_Solution_3 2 | { 3 | public interface IState 4 | { 5 | void addGumballs(GumballMachine gbm, int count); 6 | void insertCoin(GumballMachine gbm); 7 | void turnHandle(GumballMachine gbm); 8 | } 9 | } -------------------------------------------------------------------------------- /C-State Pattern/C Solution 3/NoGumballsCoin.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace C_Solution_3 4 | { 5 | public class NoGumballsCoin:IState 6 | { 7 | private static NoGumballsCoin instance = new NoGumballsCoin(); 8 | 9 | public static NoGumballsCoin getInstance 10 | { 11 | get { return instance; } 12 | } 13 | 14 | public void addGumballs(GumballMachine gbm,int count) { 15 | } 16 | 17 | public void insertCoin(GumballMachine gbm) 18 | { 19 | } 20 | 21 | public void turnHandle(GumballMachine gbm) 22 | { 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /C-State Pattern/C Solution 3/NoGumballsNoCoin.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace C_Solution_3 4 | { 5 | public class NoGumballsNoCoin:IState 6 | { 7 | private static NoGumballsNoCoin instance = new NoGumballsNoCoin(); 8 | 9 | private NoGumballsNoCoin() { } 10 | 11 | public static NoGumballsNoCoin getInstance 12 | { 13 | get { return instance; } 14 | } 15 | 16 | public void addGumballs(GumballMachine gbm, int count) 17 | { 18 | WriteLine("Added gumballs!"); 19 | gbm.addCount(count); 20 | gbm.setState(GumballsNoCoin.getInstance); 21 | } 22 | 23 | public void insertCoin(GumballMachine gbm) 24 | { 25 | WriteLine("Coin is Inserted!"); 26 | gbm.setState(NoGumballsCoin.getInstance); 27 | } 28 | 29 | public void turnHandle(GumballMachine gbm) 30 | { 31 | WriteLine("Insert Coin"); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /C-State Pattern/C Solution 3/Program.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace C_Solution_3 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | GumballMachine m1 = new GumballMachine(); 10 | m1.turnHandle(); 11 | WriteLine(m1); 12 | m1.addGumballs(10); 13 | WriteLine(m1); 14 | m1.turnHandle(); 15 | WriteLine(m1); 16 | m1.insertCoin(); 17 | WriteLine(m1); 18 | m1.turnHandle(); 19 | WriteLine(m1); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /C-State Pattern/C-State Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /C-State Pattern/C-State Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace C_State_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | namespace D_Solution_1 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | int[] arr = { 10, 6, 7, 8, 3}; 8 | Sorter sorter = new Sorter(arr); 9 | sorter.sort("bubble_sort"); 10 | sorter.sort("merge_sort"); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 1/Sorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D_Solution_1 4 | { 5 | public class Sorter 6 | { 7 | private int[] array; 8 | 9 | public Sorter(int[] arr) 10 | { 11 | array = arr; 12 | } 13 | 14 | private void bubble_sort() 15 | { 16 | Console.WriteLine("sorting array using bubble sort algorithm"); 17 | } 18 | 19 | private void merge_sort() 20 | { 21 | Console.WriteLine("sorting array using merge sort algorithm"); 22 | } 23 | 24 | public void sort(string algo) 25 | { 26 | if (algo.Equals("bubble_sort")) 27 | bubble_sort(); 28 | else if (algo.Equals("merge_sort")) 29 | merge_sort(); 30 | else 31 | Console.WriteLine("Invalid Sort Algorithm"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 2/BubbleSorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace D_Solution_2 8 | { 9 | public class BubbleSorter : Sorter 10 | { 11 | public BubbleSorter(int[] arr) : base(arr) 12 | { 13 | } 14 | 15 | public override void sort() 16 | { 17 | Console.WriteLine("sorting array using bubble sort algorithm"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 2/MergeSorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D_Solution_2 4 | { 5 | class MergeSorter : Sorter 6 | { 7 | public MergeSorter(int[] arr) : base(arr) 8 | { 9 | } 10 | 11 | public override void sort() 12 | { 13 | Console.WriteLine("sorting array using merge sort algorithm"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace D_Solution_2 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | int[] arr = { 345, 45, 567, 56, 45, 634, 745, }; 14 | 15 | Sorter sorter = new BubbleSorter(arr); 16 | sorter.sort(); 17 | 18 | sorter = new MergeSorter(arr); 19 | sorter.sort(); 20 | 21 | sorter = new QuickSorter(arr); 22 | sorter.sort(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 2/QuickSorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D_Solution_2 4 | { 5 | public class QuickSorter : Sorter 6 | { 7 | public QuickSorter(int[] arr) : base(arr) 8 | { 9 | } 10 | 11 | public override void sort() 12 | { 13 | Console.WriteLine("sort the array using quicksort algorithm"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 2/Sorter.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace D_Solution_2 3 | { 4 | public abstract class Sorter 5 | { 6 | private int[] array; 7 | 8 | public Sorter(int[] arr) 9 | { 10 | array = arr; 11 | } 12 | 13 | public abstract void sort(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 3/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 3/AscBubbleSorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace D_Solution_3 8 | { 9 | public class AscBubbleSorter : Sorter 10 | { 11 | public AscBubbleSorter(int[] arr) : base(arr) 12 | { 13 | } 14 | 15 | public override void sort() 16 | { 17 | Console.WriteLine("sorting array in ascending order using bubble sort algorithm"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 3/AscMergeSorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D_Solution_3 4 | { 5 | public class AscMergeSorter : Sorter 6 | { 7 | public AscMergeSorter(int[] arr) : base(arr) 8 | { 9 | } 10 | 11 | public override void sort() 12 | { 13 | Console.WriteLine("sorting array in ascending order using merge sort algorithm"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 3/DescBubbleSorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D_Solution_3 4 | { 5 | public class DescBubbleSorter : Sorter 6 | { 7 | public DescBubbleSorter(int[] arr) : base(arr) 8 | { 9 | } 10 | 11 | public override void sort() 12 | { 13 | Console.WriteLine("sorting array in descending order using bubble sort algorithm"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 3/DescMergeSorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D_Solution_3 4 | { 5 | public class DescMergeSorter : Sorter 6 | { 7 | public DescMergeSorter(int[] arr) : base(arr) 8 | { 9 | } 10 | 11 | public override void sort() 12 | { 13 | Console.WriteLine("sorting array in descending order using merge sort algorithm"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 3/Program.cs: -------------------------------------------------------------------------------- 1 | namespace D_Solution_3 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | int[] arr = { 5, 346, 3, 523, 634, 76, 234, 2346, 3, 35 }; 8 | 9 | Sorter sorter = new AscBubbleSorter(arr); 10 | sorter.sort(); 11 | 12 | sorter = new DescMergeSorter(arr); 13 | sorter.sort(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 3/Sorter.cs: -------------------------------------------------------------------------------- 1 | namespace D_Solution_3 2 | { 3 | public abstract class Sorter 4 | { 5 | private int[] array; 6 | 7 | public Sorter(int[] arr) 8 | { 9 | array = arr; 10 | } 11 | 12 | public abstract void sort(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 4/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 4/BubbleSortAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D_Solution_4 4 | { 5 | public class BubbleSortAlgorithm : ISortAlgorithm 6 | { 7 | public void sort() 8 | { 9 | Console.WriteLine("Sort the array using bubble sort"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 4/ISortAlgorithm.cs: -------------------------------------------------------------------------------- 1 | namespace D_Solution_4 2 | { 3 | public interface ISortAlgorithm 4 | { 5 | void sort(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 4/MergeSortAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D_Solution_4 4 | { 5 | public class MergeSortAlgorithm : ISortAlgorithm 6 | { 7 | public void sort() 8 | { 9 | Console.WriteLine("Sort array using mergesort"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 4/Program.cs: -------------------------------------------------------------------------------- 1 | namespace D_Solution_4 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | int[] arr = { 34, 534, 45, 23, 346, 34, 5 }; 8 | 9 | Sorter sorter = new Sorter(arr); 10 | 11 | ISortAlgorithm algo = new BubbleSortAlgorithm(); 12 | sorter.setAlgorithm(algo); 13 | sorter.sort(); 14 | 15 | algo = new MergeSortAlgorithm(); 16 | sorter.setAlgorithm(algo); 17 | sorter.sort(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 4/Sorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace D_Solution_4 8 | { 9 | public class Sorter 10 | { 11 | private int[] array; 12 | private ISortAlgorithm algo; 13 | 14 | public Sorter(int[] arr) 15 | { 16 | array = arr; 17 | } 18 | 19 | public void setAlgorithm(ISortAlgorithm algo) 20 | { 21 | this.algo = algo; 22 | } 23 | 24 | public void sort() 25 | { 26 | algo.sort(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 5/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 5/AscComparator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D_Solution_5 4 | { 5 | public class AscComparator : IComparator 6 | { 7 | public int compare(int e1, int e2) 8 | { 9 | return 0; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 5/BubbleSortAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D_Solution_5 4 | { 5 | public class BubbleSortAlgorithm : ISortAlgorithm 6 | { 7 | private IComparator comparator; 8 | 9 | public BubbleSortAlgorithm(IComparator comparator) 10 | { 11 | this.comparator = comparator; 12 | } 13 | 14 | public void sort() 15 | { 16 | Console.WriteLine("Sort the array using bubble sort"); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 5/IComparator.cs: -------------------------------------------------------------------------------- 1 | namespace D_Solution_5 2 | { 3 | public interface IComparator 4 | { 5 | int compare(int e1, int e2); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 5/ISortAlgorithm.cs: -------------------------------------------------------------------------------- 1 | namespace D_Solution_5 2 | { 3 | public interface ISortAlgorithm 4 | { 5 | void sort(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 5/MergeSortAlgorithm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D_Solution_5 4 | { 5 | public class MergeSortAlgorithm : ISortAlgorithm 6 | { 7 | private IComparator comparator; 8 | 9 | public MergeSortAlgorithm(IComparator comparator) 10 | { 11 | this.comparator = comparator; 12 | } 13 | 14 | public void sort() 15 | { 16 | Console.WriteLine("Sort array using mergesort"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 5/Program.cs: -------------------------------------------------------------------------------- 1 | namespace D_Solution_5 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | int[] arr = { 5, 346, 34, 634, 6, 346, 4 }; 8 | 9 | Sorter sorter = new Sorter(arr); 10 | 11 | IComparator comparator = new AscComparator(); 12 | 13 | ISortAlgorithm algo = new BubbleSortAlgorithm(comparator); 14 | sorter.setAlgorithm(algo); 15 | sorter.sort(); 16 | 17 | algo = new MergeSortAlgorithm(comparator); 18 | sorter.setAlgorithm(algo); 19 | sorter.sort(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D Solution 5/Sorter.cs: -------------------------------------------------------------------------------- 1 | namespace D_Solution_5 2 | { 3 | public class Sorter 4 | { 5 | private int[] array; 6 | private ISortAlgorithm algo; 7 | 8 | public Sorter(int[] arr) 9 | { 10 | array = arr; 11 | } 12 | 13 | public void setAlgorithm(ISortAlgorithm algo) 14 | { 15 | this.algo = algo; 16 | } 17 | 18 | public void sort() 19 | { 20 | algo.sort(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D-Strategy Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /D-Strategy Pattern/D-Strategy Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace D_Strategy_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 1/CurrentCondtionsDisplay.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace E_Solution_1 4 | { 5 | public class CurrentCondtionsDisplay 6 | { 7 | public Weather weather; 8 | 9 | public void update(Weather weather) 10 | { 11 | this.weather = weather; 12 | WriteLine("Temperature:" + weather.getTemp()); 13 | WriteLine("Pressure:" + weather.getPressure()); 14 | WriteLine("Humidity:" + weather.getHumidity()); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 1/ForecastDisplay.cs: -------------------------------------------------------------------------------- 1 | namespace E_Solution_1 2 | { 3 | public class ForecastDisplay 4 | { 5 | private Weather weather_forecast; 6 | 7 | public ForecastDisplay() 8 | { 9 | weather_forecast = new Weather(); 10 | } 11 | 12 | public void update(Weather weather) 13 | { 14 | weather_forecast.setTemp(weather.getTemp() * 2 + 3); 15 | weather_forecast.setPressure(weather.getPressure() * 10 - 5); 16 | weather_forecast.setHumidity(weather.getHumidity() + 4); 17 | System.Console.WriteLine("Forecasted Temperature:" + weather.getTemp()); 18 | System.Console.WriteLine("Forecasted Pressure:" + weather.getPressure()); 19 | System.Console.WriteLine("Forecasted Humidity:" + weather.getHumidity()); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static System.Console; 3 | 4 | namespace E_Solution_1 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | WeatherStation ws = new WeatherStation(); 11 | 12 | string X = ""; 13 | do 14 | { 15 | WriteLine("Enter the sensor values:"); 16 | float temp = Convert.ToSingle(ReadLine()); 17 | float pressure = Convert.ToSingle(ReadLine()); 18 | float humidity = Convert.ToSingle(ReadLine()); 19 | ws.notify(temp, pressure, humidity); 20 | WriteLine("Enter to Continue, X to Exit."); 21 | X = ReadLine(); 22 | } while (!X.Equals("X")); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 1/StatisticsDisplay.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace E_Solution_1 4 | { 5 | public class StatisticsDisplay 6 | { 7 | private float minTemp; 8 | private float maxTemp; 9 | private float minPressure; 10 | private float maxPressure; 11 | 12 | public StatisticsDisplay() 13 | { 14 | minTemp = float.MaxValue; 15 | maxTemp = float.MinValue; 16 | } 17 | 18 | public void update(Weather weather) 19 | { 20 | minTemp = Math.Min(minTemp, weather.getTemp()); 21 | maxTemp = Math.Max(maxTemp, weather.getTemp()); 22 | minPressure = Math.Min(minPressure, weather.getPressure()); 23 | maxPressure = Math.Max(maxPressure, weather.getPressure()); 24 | Console.WriteLine("MinTemp:" + minTemp + ",MaxTemp:" + maxTemp); 25 | Console.WriteLine("MinPresure:" + minPressure + ",MaxPressure:" + maxPressure); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 1/WeatherStation.cs: -------------------------------------------------------------------------------- 1 | namespace E_Solution_1 2 | { 3 | public class WeatherStation 4 | { 5 | private CurrentCondtionsDisplay cDisplay; 6 | private StatisticsDisplay sDisplay; 7 | private ForecastDisplay fDisplay; 8 | 9 | public WeatherStation() 10 | { 11 | cDisplay = new CurrentCondtionsDisplay(); 12 | sDisplay = new StatisticsDisplay(); 13 | fDisplay = new ForecastDisplay(); 14 | } 15 | 16 | public void notify(float temp, float pressure, float humidity) 17 | { 18 | Weather weather = new Weather(temp, pressure, humidity); 19 | cDisplay.update(weather); 20 | sDisplay.update(weather); 21 | fDisplay.update(weather); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 2/CurrentConditionsDisplay.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace E_Solution_2 4 | { 5 | public class CurrentConditionsDisplay : IDisplay 6 | { 7 | private Weather weather; 8 | 9 | public void update(Weather weather) 10 | { 11 | this.weather = weather; 12 | WriteLine("Temperature:" + weather.getTemp()); 13 | WriteLine("Pressure:" + weather.getPressure()); 14 | WriteLine("Humidity:" + weather.getHumidity()); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 2/ForecastDisplay.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace E_Solution_2 4 | { 5 | public class ForecastDisplay : IDisplay 6 | { 7 | public Weather weather_forecast; 8 | 9 | public ForecastDisplay() 10 | { 11 | weather_forecast = new Weather(); 12 | } 13 | public void update(Weather weather) 14 | { 15 | weather_forecast.setTemp(weather.getTemp() * 2 + 3); 16 | weather_forecast.setPressure(weather.getPressure() * 10 - 5); 17 | weather_forecast.setHumidity(weather.getHumidity() + 4); 18 | WriteLine("Forecasted Temperature:" + weather.getTemp()); 19 | WriteLine("Forecasted Pressure:" + weather.getPressure()); 20 | WriteLine("Forecasted Humidity:" + weather.getHumidity()); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 2/IDisplay.cs: -------------------------------------------------------------------------------- 1 | namespace E_Solution_2 2 | { 3 | public interface IDisplay 4 | { 5 | void update(Weather weather); 6 | } 7 | } -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static System.Console; 3 | 4 | namespace E_Solution_2 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | WeatherStation ws = new WeatherStation(); 11 | ws.subscribe(new CurrentConditionsDisplay()); 12 | ws.subscribe(new StatisticsDisplay()); 13 | ws.subscribe(new ForecastDisplay()); 14 | 15 | string c = "C"; 16 | while (c.Equals("C")) 17 | { 18 | WriteLine("Enter the sensor values:"); 19 | float temp = Convert.ToSingle(ReadLine()); 20 | float pressure = Convert.ToSingle(ReadLine()); 21 | float humidity = Convert.ToSingle(ReadLine()); 22 | ws.notify(temp, pressure, humidity); 23 | c = ReadLine(); 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 2/StatisticsDisplay.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static System.Console; 3 | 4 | namespace E_Solution_2 5 | { 6 | public class StatisticsDisplay : IDisplay 7 | { 8 | private float minTemp; 9 | private float maxTemp; 10 | private float minPressure; 11 | private float maxPressure; 12 | 13 | public StatisticsDisplay() 14 | { 15 | minTemp = float.MaxValue; 16 | maxTemp = float.MinValue; 17 | } 18 | 19 | public void update(Weather weather) 20 | { 21 | minTemp = Math.Min(minTemp, weather.getTemp()); 22 | maxTemp = Math.Max(maxTemp, weather.getTemp()); 23 | minPressure = Math.Min(minPressure, weather.getPressure()); 24 | maxPressure = Math.Max(maxPressure, weather.getPressure()); 25 | WriteLine("MinTemp:" + minTemp + ",MaxTemp:" + maxTemp); 26 | WriteLine("MinPresure:" + minPressure + ",MaxPressure:" + maxPressure); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /E-Observer Pattern/E Solution 2/WeatherStation.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace E_Solution_2 4 | { 5 | public class WeatherStation 6 | { 7 | private List display_units; 8 | 9 | public WeatherStation() 10 | { 11 | display_units = new List(); 12 | } 13 | 14 | public void subscribe(IDisplay display) 15 | { 16 | display_units.Add(display); 17 | } 18 | 19 | public void unsubscribe(IDisplay display) 20 | { 21 | display_units.Remove(display); 22 | } 23 | 24 | public void notify(float temp, float pressure, float humidity) 25 | { 26 | Weather weather = new Weather(temp, pressure, humidity); 27 | foreach (var display in display_units) 28 | display.update(weather); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /E-Observer Pattern/E-Observer Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /E-Observer Pattern/E-Observer Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace E_Observer_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 1/CEditBox.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace F_Solution_1 4 | { 5 | public class CEditBox 6 | { 7 | private FEditBox fEditBox; 8 | private TempBar tempBar; 9 | private float tempInC; 10 | 11 | public CEditBox(TempBar tempBar, float tempInC) 12 | { 13 | this.tempBar = tempBar; 14 | this.tempInC = tempInC; 15 | } 16 | 17 | public void change(float temp) 18 | { 19 | WriteLine("Edited value in Ceditbox:" + temp); 20 | fEditBox.update(Utils.convertCF(temp)); 21 | tempBar.display(Utils.convertCF(temp)); 22 | } 23 | 24 | public void update(float temp) 25 | { 26 | tempInC = temp; 27 | WriteLine("CEditBox: " + tempInC); 28 | } 29 | 30 | public void serfEditBox(FEditBox fEditBox) 31 | { 32 | this.fEditBox = fEditBox; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 1/CLowerButton.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_1 2 | { 3 | public class CLowerButton 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 1/CRaiseButton.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_1 2 | { 3 | public class CRaiseButton 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 1/FLowerButton.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_1 2 | { 3 | public class FLowerButton 4 | { 5 | private FEditBox fEditBox; 6 | private CEditBox cEditBox; 7 | private TempBar tempBar; 8 | 9 | public FLowerButton(FEditBox fEditBox, CEditBox cEditBox, TempBar tempBar) 10 | { 11 | this.fEditBox = fEditBox; 12 | this.cEditBox = cEditBox; 13 | this.tempBar = tempBar; 14 | } 15 | 16 | public void onClick() 17 | { 18 | System.Console.WriteLine("Lower Button for Forenheit is pressed"); 19 | float f = fEditBox.getTempInF() - 5; 20 | fEditBox.update(f); 21 | cEditBox.update(Utils.convertFC(f)); 22 | tempBar.display(f); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 1/FRaiseButton.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_1 2 | { 3 | public class FRaiseButton 4 | { 5 | private FEditBox fEditBox; 6 | private CEditBox cEditBox; 7 | private TempBar tempBar; 8 | 9 | public FRaiseButton(FEditBox fEditBox, CEditBox cEditBox, TempBar tempBar) 10 | { 11 | this.fEditBox = fEditBox; 12 | this.cEditBox = cEditBox; 13 | this.tempBar = tempBar; 14 | } 15 | 16 | public void onClick() 17 | { 18 | System.Console.WriteLine("Raise Button for Forenheit is pressed"); 19 | float f = fEditBox.getTempInF() + 5; 20 | fEditBox.update(f); 21 | cEditBox.update(Utils.convertFC(f)); 22 | tempBar.display(f); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_1 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | TempBar tempBar = new TempBar(); 8 | FEditBox fEditBox = new FEditBox(tempBar, 0); 9 | CEditBox cEditBox = new CEditBox(tempBar, 0); 10 | fEditBox.setcEditBox(cEditBox); 11 | // cEditBox.setfEditBox(fEditBox); 12 | // Circular Dependency 13 | FRaiseButton fRaiseButton = new FRaiseButton(fEditBox, cEditBox, tempBar); 14 | FLowerButton fLowerButton = new FLowerButton(fEditBox, cEditBox, tempBar); 15 | 16 | fEditBox.change(30); 17 | cEditBox.change(43); 18 | fRaiseButton.onClick(); 19 | fLowerButton.onClick(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 1/TempBar.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_1 2 | { 3 | public class TempBar 4 | { 5 | private float temp; 6 | 7 | public void display(float temp) 8 | { 9 | this.temp = temp; 10 | System.Console.WriteLine("Temp bar: " + temp); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 1/Utils.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_1 2 | { 3 | public class Utils 4 | { 5 | public static float convertCF(float tempInC) 6 | { 7 | return tempInC * 9.0f / 5; 8 | } 9 | 10 | public static float convertFC(float tempInF) 11 | { 12 | return tempInF * 5.0f / 9; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/CEditBox.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace F_Solution_2 4 | { 5 | public class CEditBox : IEditBox 6 | { 7 | private IMediator mediator; 8 | private float tempInC; 9 | 10 | public CEditBox(IMediator mediator, float tempInC) 11 | { 12 | this.mediator = mediator; 13 | this.tempInC = tempInC; 14 | } 15 | 16 | public void change(float temp) 17 | { 18 | WriteLine("Edited value in Ceditbox:" + temp); 19 | mediator.notify(this, temp); 20 | } 21 | 22 | public float getTemp() 23 | { 24 | return tempInC; 25 | } 26 | 27 | public void update(float temp) 28 | { 29 | tempInC = temp; 30 | WriteLine("CEditBox: " + tempInC); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/CLowerButton.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_2 2 | { 3 | public class CLowerButton : IButton 4 | { 5 | private IMediator mediator; 6 | 7 | public CLowerButton(IMediator mediator) 8 | { 9 | this.mediator = mediator; 10 | } 11 | 12 | public void onClick() 13 | { 14 | System.Console.WriteLine("Lower Button for Celsius is pressed"); 15 | mediator.notify(this); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/CRaiseButton.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_2 2 | { 3 | public class CRaiseButton : IButton 4 | { 5 | private IMediator mediator; 6 | 7 | public CRaiseButton(IMediator mediator) 8 | { 9 | this.mediator = mediator; 10 | } 11 | 12 | public void onClick() 13 | { 14 | System.Console.WriteLine("Raise Button for Celsius is pressed"); 15 | mediator.notify(this); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/FEditBox.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace F_Solution_2 4 | { 5 | public class FEditBox : IEditBox 6 | { 7 | private IMediator mediator; 8 | private float tempInF; 9 | 10 | public FEditBox(IMediator mediator, float tempInF) 11 | { 12 | this.mediator = mediator; 13 | this.tempInF = tempInF; 14 | } 15 | 16 | public void change(float temp) 17 | { 18 | WriteLine("Edited value in Feditbox:" + temp); 19 | mediator.notify(this, temp); 20 | } 21 | 22 | public float getTemp() 23 | { 24 | return tempInF; 25 | } 26 | 27 | public void update(float temp) 28 | { 29 | tempInF = temp; 30 | WriteLine("FEditbox:" + tempInF); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/FLowerButton.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_2 2 | { 3 | public class FLowerButton : IButton 4 | { 5 | private IMediator mediator; 6 | 7 | public FLowerButton(IMediator mediator) 8 | { 9 | this.mediator = mediator; 10 | } 11 | 12 | public void onClick() 13 | { 14 | System.Console.WriteLine("Lower Button for Forenheit is pressed"); 15 | mediator.notify(this); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/FRaiseButton.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_2 2 | { 3 | public class FRaiseButton : IButton 4 | { 5 | public IMediator mediator; 6 | 7 | public FRaiseButton(IMediator mediator) 8 | { 9 | this.mediator = mediator; 10 | 11 | } 12 | 13 | public void onClick() 14 | { 15 | System.Console.WriteLine("Raise Button for Forenheit is pressed"); 16 | mediator.notify(this); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/IButton.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_2 2 | { 3 | public interface IButton 4 | { 5 | void onClick(); 6 | } 7 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/IEditBox.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_2 2 | { 3 | public interface IEditBox 4 | { 5 | void change(float temp); 6 | void update(float temp); 7 | float getTemp(); 8 | } 9 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/IMediator.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_2 2 | { 3 | public interface IMediator 4 | { 5 | void notify(IEditBox editbox, float temp); 6 | void notify(IButton button); 7 | } 8 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/TempBar.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_2 2 | { 3 | public class TempBar 4 | { 5 | private float temp; 6 | 7 | public void display(float temp) 8 | { 9 | this.temp = temp; 10 | System.Console.WriteLine("Temp bar: " + temp); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 2/Utils.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_2 2 | { 3 | public class Utils 4 | { 5 | public static float convertCF(float tempInC) 6 | { 7 | return tempInC * 9.0f / 5; 8 | } 9 | 10 | public static float convertFC(float tempInF) 11 | { 12 | return tempInF * 5.0f / 9; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/CEditBox.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace F_Solution_3 4 | { 5 | public class CEditBox : IWidget 6 | { 7 | private TempDialogMediator mediator; 8 | private float tempInC; 9 | 10 | public CEditBox(TempDialogMediator mediator, float tempInC) 11 | { 12 | this.mediator = mediator; 13 | this.tempInC = tempInC; 14 | } 15 | 16 | public float getTemp() 17 | { 18 | return tempInC; 19 | } 20 | 21 | public void change(float temp) 22 | { 23 | WriteLine("Edited value in Ceditbox:" + temp); 24 | mediator.notify(this, temp); 25 | } 26 | 27 | public void change() 28 | { 29 | } 30 | 31 | public void update(float temp) 32 | { 33 | tempInC = temp; 34 | WriteLine("CEditBox:" + tempInC); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/CLowerButton.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace F_Solution_3 4 | { 5 | public class CLowerButton : IWidget 6 | { 7 | public TempDialogMediator mediator; 8 | 9 | public CLowerButton(TempDialogMediator mediator) 10 | { 11 | this.mediator = mediator; 12 | } 13 | 14 | public void change(float temp) 15 | { 16 | WriteLine("Lower Button for Celsius is pressed"); 17 | // mediator.notify(); 18 | } 19 | 20 | public void change() 21 | { 22 | } 23 | 24 | public void update(float temp) 25 | { 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/CRaiseButton.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace F_Solution_3 4 | { 5 | public class CRaiseButton : IWidget 6 | { 7 | private TempDialogMediator mediator; 8 | 9 | public CRaiseButton(TempDialogMediator mediator) 10 | { 11 | this.mediator = mediator; 12 | } 13 | 14 | public void change(float temp) 15 | { 16 | WriteLine("Raise Button for Celsius is pressed"); 17 | // mediator.notify(); 18 | } 19 | 20 | public void change() 21 | { 22 | } 23 | 24 | public void update(float temp) 25 | { 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/FEditBox.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace F_Solution_3 4 | { 5 | public class FEditBox : IWidget 6 | { 7 | private TempDialogMediator mediator; 8 | private float tempInF; 9 | 10 | public FEditBox(TempDialogMediator mediator, float tempInF) 11 | { 12 | this.mediator = mediator; 13 | this.tempInF = tempInF; 14 | } 15 | 16 | public float getTemp() 17 | { 18 | return tempInF; 19 | } 20 | 21 | public void change(float temp) 22 | { 23 | WriteLine("Edited value in Feditbox:" + temp); 24 | mediator.notify(this, temp); 25 | } 26 | 27 | public void change() 28 | { 29 | } 30 | 31 | public void update(float temp) 32 | { 33 | tempInF = temp; 34 | WriteLine("FEditbox:" + tempInF); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/FLowerButton.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_3 2 | { 3 | public class FLowerButton : IWidget 4 | { 5 | private TempDialogMediator mediator; 6 | 7 | public FLowerButton(TempDialogMediator mediator) 8 | { 9 | this.mediator = mediator; 10 | } 11 | 12 | public void change(float temp) 13 | { 14 | System.Console.WriteLine("Lower Button for Forenheit is pressed"); 15 | // mediator.notify(); 16 | } 17 | 18 | public void change() 19 | { 20 | } 21 | 22 | public void update(float temp) 23 | { 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/FRaiseButton.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_3 2 | { 3 | public class FRaiseButton : IWidget 4 | { 5 | private TempDialogMediator mediator; 6 | 7 | public FRaiseButton(TempDialogMediator mediator) 8 | { 9 | this.mediator = mediator; 10 | } 11 | 12 | public void change(float temp) 13 | { 14 | System.Console.WriteLine("Raise Button for Forenheit is pressed"); 15 | // mediator.notify(); 16 | } 17 | 18 | public void change() 19 | { 20 | } 21 | 22 | public void update(float temp) 23 | { 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/IMediator.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_3 2 | { 3 | public interface IMediator 4 | { 5 | void notify(IWidget widget, float value); 6 | } 7 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/IWidget.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_3 2 | { 3 | public interface IWidget 4 | { 5 | void update(float temp); 6 | void change(float temp); 7 | void change(); 8 | } 9 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/TempBar.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_3 2 | { 3 | public class TempBar : IWidget 4 | { 5 | private float temp; 6 | 7 | public void change(float temp) 8 | { 9 | } 10 | 11 | public void change() 12 | { 13 | } 14 | 15 | public void update(float temp) 16 | { 17 | this.temp = temp; 18 | System.Console.WriteLine("Temp bar: " + temp); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/TempDialogMediator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace F_Solution_3 4 | { 5 | public class TempDialogMediator 6 | { 7 | private List widgets; 8 | 9 | public TempDialogMediator() 10 | { 11 | widgets = new List(); 12 | } 13 | 14 | public void addWidget(IWidget widget) 15 | { 16 | widgets.Add(widget); 17 | } 18 | 19 | public void notify(IWidget widget, float temp) 20 | { 21 | widgets.ForEach(wd => 22 | { 23 | if (wd != widget) 24 | wd.update(temp); 25 | }); 26 | } 27 | //when button is a source of event, how do we know which editbox value have to read? 28 | } 29 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F Solution 3/Utils.cs: -------------------------------------------------------------------------------- 1 | namespace F_Solution_3 2 | { 3 | public class Utils 4 | { 5 | public static float convertCF(float tempInC) 6 | { 7 | return tempInC * 9.0f / 5; 8 | } 9 | 10 | public static float convertFC(float tempInF) 11 | { 12 | return tempInF * 5.0f / 9; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /F-Mediator Pattern/F-Mediator Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /F-Mediator Pattern/F-Mediator Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace F_Mediator_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /G-Decorator Pattern/G-Decorator Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /G-Decorator Pattern/G-Decorator Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace G_Decorator_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace H_Solution_1 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Square[] squares = new Square[20]; 10 | 11 | squares[0] = new Square(0, 10); 12 | squares[1] = new Square(1, 15); 13 | 14 | squares[0].move(5, 5); 15 | squares[0].scale(2); 16 | Console.WriteLine(squares[0].toString()); 17 | 18 | squares[1].scale(3); 19 | Console.WriteLine(squares[1].toString()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 1/Square.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_1 2 | { 3 | public class Square 4 | { 5 | private int id; 6 | private int length; 7 | private int x; 8 | private int y; 9 | 10 | public Square(int id, int length) 11 | { 12 | this.id = id; 13 | this.length = length; 14 | this.x = 0; 15 | this.y = 0; 16 | } 17 | 18 | public void move(int j,int k) 19 | { 20 | x += j; 21 | y += k; 22 | } 23 | 24 | public void scale(int j) 25 | { 26 | length *= j; 27 | } 28 | 29 | public string toString() 30 | { 31 | return "Square [id=" + id + ", length=" + length + ", x=" + x + ", y=" 32 | + y + "]"; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 2/AbstractCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_2 2 | { 3 | public abstract class AbstractCommand 4 | { 5 | private string command; 6 | private Square square; 7 | 8 | public AbstractCommand(string command, Square square) 9 | { 10 | this.command = command; 11 | this.square = square; 12 | } 13 | 14 | public string getCommand() 15 | { 16 | return command; 17 | } 18 | 19 | public Square getSquare() 20 | { 21 | return square; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 2/MoveCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_2 2 | { 3 | public class MoveCommand : AbstractCommand 4 | { 5 | private int j; 6 | private int k; 7 | 8 | public MoveCommand(string command, Square square, int j, int k) : base(command, square) 9 | { 10 | this.j = j; 11 | this.k = k; 12 | } 13 | 14 | public int getJ() 15 | { 16 | return j; 17 | } 18 | public int getK() 19 | { 20 | return k; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 2/Program.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_2 2 | { 3 | public class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | Square[] squares = new Square[20]; 8 | 9 | squares[0] = new Square(0, 10); 10 | squares[1] = new Square(1, 15); 11 | 12 | Invoker invoker = new Invoker(); 13 | 14 | invoker.move(squares[0], 5, 5); 15 | invoker.scale(squares[0], 2); 16 | invoker.print(squares[0]); 17 | 18 | invoker.scale(squares[1], 3); 19 | invoker.print(squares[1]); 20 | 21 | invoker.undo(); 22 | 23 | invoker.print(squares[1]); 24 | invoker.print(squares[0]); 25 | } 26 | } 27 | } 28 | 29 | //Problem: invoker class requires downcasting and requires modifications for new commands and new shapes -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 2/ScaleCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_2 2 | { 3 | public class ScaleCommand : AbstractCommand 4 | { 5 | private int j; 6 | public ScaleCommand(string command, Square square, int j) : base(command, square) 7 | { 8 | this.j = j; 9 | } 10 | 11 | public int getJ() 12 | { 13 | return j; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 3/AbstractCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_3 2 | { 3 | public abstract class AbstractCommand 4 | { 5 | protected Square square; 6 | 7 | public AbstractCommand(Square square) 8 | { 9 | this.square = square; 10 | } 11 | 12 | public Square getSquare() 13 | { 14 | return square; 15 | } 16 | 17 | public abstract void undo(); 18 | } 19 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 3/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 3/Invoker.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_3 2 | { 3 | public class Invoker 4 | { 5 | private AbstractCommand lastCommand; 6 | 7 | public void move(Square square, int j, int k) 8 | { 9 | lastCommand = new MoveCommand(square, j, k); 10 | square.move(j, k); 11 | } 12 | 13 | public void scale(Square square, int j) 14 | { 15 | lastCommand = new ScaleCommand(square, j); 16 | square.scale(j); 17 | } 18 | 19 | public void print(Square square) 20 | { 21 | System.Console.WriteLine(square.ToString()); 22 | } 23 | 24 | public void undo() 25 | { 26 | if (lastCommand == null) 27 | { 28 | System.Console.WriteLine("No Command Exist for Undo"); 29 | return; 30 | } 31 | lastCommand.undo(); 32 | lastCommand = null; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 3/MoveCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_3 2 | { 3 | public class MoveCommand : AbstractCommand 4 | { 5 | private int j; 6 | private int k; 7 | 8 | public MoveCommand(Square square, int j, int k) : base(square) 9 | { 10 | this.j = j; 11 | this.k = k; 12 | } 13 | 14 | public override void undo() 15 | { 16 | square.move_undo(j, k); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 3/Program.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_3 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | Square[] squares = new Square[20]; 8 | 9 | squares[0] = new Square(0, 10); 10 | squares[1] = new Square(1, 15); 11 | 12 | Invoker invoker = new Invoker(); 13 | 14 | invoker.move(squares[0], 5, 5); 15 | invoker.scale(squares[0], 2); 16 | invoker.print(squares[0]); 17 | 18 | invoker.scale(squares[1], 3); 19 | invoker.print(squares[1]); 20 | 21 | invoker.undo(); 22 | invoker.print(squares[1]); 23 | invoker.print(squares[0]); 24 | } 25 | } 26 | } 27 | 28 | // Problem: invoker class attached to specific shape called squares -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 3/ScaleCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_3 2 | { 3 | public class ScaleCommand : AbstractCommand 4 | { 5 | private int j; 6 | 7 | public ScaleCommand(Square square, int j) : base(square) 8 | { 9 | this.j = j; 10 | } 11 | 12 | public override void undo() 13 | { 14 | square.scale_undo(j); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 4/AbstractCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_4 2 | { 3 | public abstract class AbstractCommand 4 | { 5 | protected Square square; 6 | 7 | public AbstractCommand(Square square) 8 | { 9 | this.square = square; 10 | } 11 | 12 | public Square getSquare() 13 | { 14 | return square; 15 | } 16 | 17 | public abstract void undo(); 18 | public abstract void execute(); 19 | 20 | public bool undoable() 21 | { 22 | return true; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 4/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 4/Invoker.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_4 2 | { 3 | public class Invoker 4 | { 5 | private AbstractCommand lastCommand; 6 | 7 | public void execute(AbstractCommand command) 8 | { 9 | if (command.undoable()) 10 | lastCommand = command; 11 | command.execute(); 12 | } 13 | 14 | public void undo() 15 | { 16 | if (lastCommand == null) 17 | { 18 | System.Console.WriteLine("No command exist for undo"); 19 | return; 20 | } 21 | lastCommand.undo(); 22 | lastCommand = null; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 4/MoveCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_4 2 | { 3 | public class MoveCommand : AbstractCommand 4 | { 5 | private int j; 6 | private int k; 7 | 8 | public MoveCommand(Square square, int j, int k) : base(square) 9 | { 10 | this.j = j; 11 | this.k = k; 12 | } 13 | 14 | public override void execute() 15 | { 16 | square.move(j, k); 17 | } 18 | 19 | public override void undo() 20 | { 21 | square.move_undo(j, k); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 4/PrintCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_4 2 | { 3 | public class PrintCommand : AbstractCommand 4 | { 5 | public PrintCommand(Square square) : base(square) 6 | { 7 | } 8 | 9 | public override void execute() 10 | { 11 | System.Console.WriteLine(square.ToString()); 12 | } 13 | 14 | public override void undo() 15 | { 16 | // throw new NotImplementedException(); 17 | } 18 | 19 | public bool undoable() 20 | { 21 | return false; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 4/ScaleCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_4 2 | { 3 | public class ScaleCommand : AbstractCommand 4 | { 5 | private int j; 6 | 7 | public ScaleCommand(Square square, int j) : base(square) 8 | { 9 | this.j = j; 10 | } 11 | 12 | public override void execute() 13 | { 14 | square.scale(j); 15 | } 16 | 17 | public override void undo() 18 | { 19 | square.scale_undo(j); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 5/AbstractCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_5 2 | { 3 | public abstract class AbstractCommand 4 | { 5 | protected Square square; 6 | 7 | public AbstractCommand(Square square) 8 | { 9 | this.square = square; 10 | } 11 | 12 | public Square getSquare() 13 | { 14 | return square; 15 | } 16 | 17 | public abstract void undo(); 18 | 19 | public void redo() 20 | { 21 | execute(); 22 | } 23 | 24 | public abstract void execute(); 25 | 26 | public bool undoable() 27 | { 28 | return true; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 5/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 5/MoveCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_5 2 | { 3 | public class MoveCommand : AbstractCommand 4 | { 5 | private int j; 6 | private int k; 7 | 8 | public MoveCommand(Square square, int j, int k) : base(square) 9 | { 10 | this.j = j; 11 | this.k = k; 12 | } 13 | 14 | public override void execute() 15 | { 16 | square.move(j, k); 17 | } 18 | 19 | public override void undo() 20 | { 21 | square.move_undo(j, k); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 5/PrintCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_5 2 | { 3 | public class PrintCommand : AbstractCommand 4 | { 5 | public PrintCommand(Square square) : base(square) 6 | { 7 | } 8 | 9 | public override void execute() 10 | { 11 | System.Console.WriteLine(square.ToString()); 12 | } 13 | 14 | public override void undo() 15 | { 16 | } 17 | 18 | public new bool undoable() 19 | { 20 | return false; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /H-Command Pattern/H Solution 5/ScaleCommand.cs: -------------------------------------------------------------------------------- 1 | namespace H_Solution_5 2 | { 3 | public class ScaleCommand : AbstractCommand 4 | { 5 | private int j; 6 | 7 | public ScaleCommand(Square square, int j) : base(square) 8 | { 9 | this.j = j; 10 | } 11 | 12 | public override void execute() 13 | { 14 | square.scale(j); 15 | } 16 | 17 | public override void undo() 18 | { 19 | square.scale_undo(j); 20 | } 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /H-Command Pattern/H-Command Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /H-Command Pattern/H-Command Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace H_Command_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 1/BreakfastUnit.cs: -------------------------------------------------------------------------------- 1 | namespace I_Solution_1 2 | { 3 | public class BreakfastUnit 4 | { 5 | private MenuItem[] menuItems; 6 | private int size; 7 | 8 | public BreakfastUnit(int n) 9 | { 10 | menuItems = new MenuItem[n]; 11 | } 12 | 13 | public void addItem(MenuItem menuItem) 14 | { 15 | if (size == menuItems.Length) 16 | System.Console.WriteLine("You can't add any more menu items"); 17 | else 18 | menuItems[size++] = menuItem; 19 | } 20 | 21 | public MenuItem[] getMenuItems() 22 | { 23 | return menuItems; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 1/DinnerUnit.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace I_Solution_1 4 | { 5 | public class DinnerUnit 6 | { 7 | private List menuItems; 8 | 9 | public DinnerUnit() 10 | { 11 | menuItems = new List(); 12 | } 13 | 14 | public void addItem(MenuItem menuItem) 15 | { 16 | menuItems.Add(menuItem); 17 | } 18 | 19 | public List getMenuItems() 20 | { 21 | return menuItems; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 1/MenuItem.cs: -------------------------------------------------------------------------------- 1 | namespace I_Solution_1 2 | { 3 | public class MenuItem 4 | { 5 | public string name; 6 | public float price; 7 | private int qty; 8 | 9 | public MenuItem(string name, float price, int qty) : base() 10 | { 11 | this.name = name; 12 | this.price = price; 13 | this.qty = qty; 14 | } 15 | 16 | public override string ToString() 17 | { 18 | return "MenuItem [name=" + name + ", price=" + price + ", qty=" + qty + "]"; 19 | } 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 2/BreakfastUnit.cs: -------------------------------------------------------------------------------- 1 | namespace I_Solution_2 2 | { 3 | public class BreakfastUnit : Iterator 4 | { 5 | private MenuItem[] menuItems; 6 | private int size; 7 | private int current; 8 | 9 | public BreakfastUnit(int n) 10 | { 11 | menuItems = new MenuItem[n]; 12 | } 13 | 14 | public void addItem(MenuItem menuItem) 15 | { 16 | if (size == menuItems.Length) 17 | System.Console.WriteLine("You cannot add any more menu items"); 18 | else 19 | menuItems[size++] = menuItem; 20 | } 21 | 22 | public bool hasNext() 23 | { 24 | return current < menuItems.Length; 25 | } 26 | 27 | public MenuItem next() 28 | { 29 | return menuItems[current++]; 30 | } 31 | 32 | public void reset() 33 | { 34 | current = 0; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 2/DinnerUnit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace I_Solution_2 5 | { 6 | public class DinnerUnit : Iterator 7 | { 8 | private List menuItems; 9 | private int current; 10 | 11 | public DinnerUnit() 12 | { 13 | menuItems = new List(); 14 | current = 0; 15 | } 16 | 17 | public void addItem(MenuItem menuItem) 18 | { 19 | menuItems.Add(menuItem); 20 | } 21 | 22 | public bool hasNext() 23 | { 24 | return current < menuItems.Count; 25 | } 26 | 27 | public MenuItem next() 28 | { 29 | return menuItems[current++]; 30 | } 31 | 32 | public void reset() 33 | { 34 | current = 0; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 2/Iterator.cs: -------------------------------------------------------------------------------- 1 | namespace I_Solution_2 2 | { 3 | public interface Iterator 4 | { 5 | bool hasNext(); 6 | MenuItem next(); 7 | void reset(); 8 | } 9 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 2/MenuItem.cs: -------------------------------------------------------------------------------- 1 | namespace I_Solution_2 2 | { 3 | public class MenuItem 4 | { 5 | private string name; 6 | private float price; 7 | private int qty; 8 | 9 | public MenuItem(string name, float price, int qty) 10 | { 11 | this.name = name; 12 | this.price = price; 13 | this.qty = qty; 14 | } 15 | 16 | public override string ToString() 17 | { 18 | return "MenuItem [name=" + name + ", price=" + price + ", qty=" + qty + "]"; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 3/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 3/BreakfastUnit.cs: -------------------------------------------------------------------------------- 1 | namespace I_Solution_3 2 | { 3 | public class BreakfastUnit 4 | { 5 | private MenuItem[] menuItems; 6 | private int size; 7 | 8 | public BreakfastUnit(int n) 9 | { 10 | menuItems = new MenuItem[n]; 11 | } 12 | 13 | public void addItem(MenuItem menuItem) 14 | { 15 | if (size == menuItems.Length) 16 | System.Console.WriteLine("You cannot add any more menu items"); 17 | else 18 | menuItems[size++] = menuItem; 19 | } 20 | 21 | public Iterator iterator() 22 | { 23 | return new BreakfastUnitIterator(menuItems); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 3/BreakfastUnitIterator.cs: -------------------------------------------------------------------------------- 1 | namespace I_Solution_3 2 | { 3 | class BreakfastUnitIterator : Iterator 4 | { 5 | private MenuItem[] menuItems; 6 | private int current; 7 | 8 | public BreakfastUnitIterator(MenuItem[] menuItems) 9 | { 10 | this.menuItems = menuItems; 11 | } 12 | 13 | public bool hasNext() 14 | { 15 | return current < menuItems.Length; 16 | } 17 | 18 | public MenuItem next() 19 | { 20 | return menuItems[current++]; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 3/DinnerUnit.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace I_Solution_3 4 | { 5 | public class DinnerUnit 6 | { 7 | private List menuItems; 8 | 9 | public DinnerUnit() 10 | { 11 | menuItems = new List(); 12 | } 13 | 14 | public void addItem(MenuItem menuItem) 15 | { 16 | menuItems.Add(menuItem); 17 | } 18 | 19 | public Iterator iterator() 20 | { 21 | return new DinnerUnitIterator(menuItems); 22 | } 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 3/DinnerUnitIterator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace I_Solution_3 4 | { 5 | public class DinnerUnitIterator : Iterator 6 | { 7 | private List menuItems; 8 | private int current; 9 | 10 | public DinnerUnitIterator(List menuItems) 11 | { 12 | this.menuItems = menuItems; 13 | } 14 | 15 | public bool hasNext() 16 | { 17 | return current < menuItems.Count; 18 | } 19 | 20 | public MenuItem next() 21 | { 22 | return menuItems[current++]; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 3/Iterator.cs: -------------------------------------------------------------------------------- 1 | namespace I_Solution_3 2 | { 3 | public interface Iterator 4 | { 5 | bool hasNext(); 6 | MenuItem next(); 7 | } 8 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I Solution 3/MenuItem.cs: -------------------------------------------------------------------------------- 1 | namespace I_Solution_3 2 | { 3 | public class MenuItem 4 | { 5 | private string name; 6 | private float price; 7 | private int qty; 8 | 9 | public MenuItem(string name, float price, int qty) 10 | { 11 | this.name = name; 12 | this.price = price; 13 | this.qty = qty; 14 | } 15 | 16 | public new string ToString() 17 | { 18 | return "MenuItem [name=" + name + ", price=" + price + ", qty=" + qty + "]"; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /I-Iterator Pattern/I-Iterator Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /I-Iterator Pattern/I-Iterator Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace I_Iterator_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /J-Adapter Pattern/J Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /J-Adapter Pattern/J Solution 1/IStack.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | namespace J_Solution_1 5 | { 6 | public interface IStack 7 | { 8 | void push(int e); 9 | int? pop(); 10 | IEnumerator iterator(); 11 | int size(); 12 | } 13 | } -------------------------------------------------------------------------------- /J-Adapter Pattern/J Solution 1/LinkedStack.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace J_Solution_1 4 | { 5 | public class LinkedStack : LinkedList, IStack 6 | { 7 | public IEnumerator iterator() 8 | { 9 | return GetEnumerator(); 10 | } 11 | 12 | public int? pop() 13 | { 14 | if (Count == 0) 15 | return null; 16 | int value = First.Value; 17 | RemoveFirst(); 18 | return value; 19 | } 20 | 21 | public void push(int e) 22 | { 23 | AddFirst(e); 24 | } 25 | 26 | public int size() 27 | { 28 | return Count; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /J-Adapter Pattern/J Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using static System.Console; 4 | 5 | namespace J_Solution_1 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | IStack stack = new LinkedStack(); 12 | Random r = new Random(); 13 | 14 | for (int i = 1; i <= 10; i++) 15 | { 16 | stack.push(r.Next(100) + 1); 17 | } 18 | 19 | IEnumerator iterator = stack.iterator(); 20 | while (iterator.MoveNext()) 21 | WriteLine(iterator.Current); 22 | 23 | WriteLine("\n" + stack.size() + "\n"); 24 | WriteLine(stack.pop()); 25 | WriteLine("\n" + stack.size() + "\n"); 26 | 27 | iterator = stack.iterator(); 28 | while (iterator.MoveNext()) 29 | WriteLine(iterator.Current); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /J-Adapter Pattern/J Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /J-Adapter Pattern/J Solution 2/IStack.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace J_Solution_2 4 | { 5 | public interface IStack 6 | { 7 | void push(int e); 8 | int? pop(); 9 | IEnumerator iterator(); 10 | int size(); 11 | } 12 | } -------------------------------------------------------------------------------- /J-Adapter Pattern/J Solution 2/LinkedStack.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace J_Solution_2 4 | { 5 | public class LinkedStack : IStack 6 | { 7 | private LinkedList list; 8 | 9 | public LinkedStack() 10 | { 11 | list = new LinkedList(); 12 | } 13 | 14 | public IEnumerator iterator() 15 | { 16 | return list.GetEnumerator(); 17 | } 18 | 19 | public int? pop() 20 | { 21 | if (list.Count == 0) 22 | return null; 23 | int value = list.First.Value; 24 | list.RemoveFirst(); 25 | return value; 26 | } 27 | 28 | public void push(int e) 29 | { 30 | list.AddFirst(e); 31 | } 32 | 33 | public int size() 34 | { 35 | return list.Count; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /J-Adapter Pattern/J Solution 2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using static System.Console; 4 | 5 | namespace J_Solution_2 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | IStack stack = new LinkedStack(); 12 | Random r = new Random(); 13 | for (int i = 1; i <= 10; i++) 14 | { 15 | stack.push(r.Next(100) + 1); 16 | } 17 | 18 | IEnumerator iterator = stack.iterator(); 19 | while (iterator.MoveNext()) 20 | WriteLine(iterator.Current); 21 | WriteLine("\n" + stack.size() + "\n"); 22 | WriteLine(stack.pop()); 23 | WriteLine("\n" + stack.size() + "\n"); 24 | 25 | iterator = stack.iterator(); 26 | while (iterator.MoveNext()) 27 | WriteLine(iterator.Current); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /J-Adapter Pattern/J-Adapter Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /J-Adapter Pattern/J-Adapter Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace J_Adapter_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 1/Program.cs: -------------------------------------------------------------------------------- 1 | namespace K_JonSkeet_1 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 1/Singleton.cs: -------------------------------------------------------------------------------- 1 | // Source: csharpindepth.com/Articles/General/Singleton.aspx 2 | // First version - not thread-safe 3 | namespace K_JonSkeet_1 4 | { 5 | // Bad code! Do not use! 6 | public sealed class Singleton 7 | { 8 | private static Singleton instance = null; 9 | private Singleton() 10 | { 11 | } 12 | public static Singleton Instance 13 | { 14 | get 15 | { 16 | if (instance == null) 17 | { 18 | instance = new Singleton(); 19 | } 20 | return instance; 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 2/Program.cs: -------------------------------------------------------------------------------- 1 | namespace K_JonSkeet_2 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 2/Singleton.cs: -------------------------------------------------------------------------------- 1 | // Source: csharpindepth.com/Articles/General/Singleton.aspx 2 | // Second version - simple thread-safety 3 | namespace K_JonSkeet_2 4 | { 5 | public sealed class Singleton 6 | { 7 | private static Singleton instance = null; 8 | private static readonly object padlock = new object(); 9 | Singleton() 10 | { 11 | } 12 | public static Singleton Instance 13 | { 14 | get 15 | { 16 | lock (padlock) 17 | { 18 | if (instance == null) 19 | { 20 | instance = new Singleton(); 21 | } 22 | return instance; 23 | } 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 3/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 3/Program.cs: -------------------------------------------------------------------------------- 1 | namespace K_JonSkeet_3 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 3/Singleton.cs: -------------------------------------------------------------------------------- 1 | // Source: csharpindepth.com/Articles/General/Singleton.aspx 2 | // Third version - attempted thread-safety using double-check locking 3 | namespace K_JonSkeet_3 4 | { 5 | // Bad code! Do not use! 6 | public sealed class Singleton 7 | { 8 | private static Singleton instance = null; 9 | private static readonly object padlock = new object(); 10 | Singleton() 11 | { 12 | } 13 | public static Singleton Instance 14 | { 15 | get 16 | { 17 | if (instance == null) 18 | { 19 | lock (padlock) 20 | { 21 | if (instance == null) 22 | { 23 | instance = new Singleton(); 24 | } 25 | } 26 | } 27 | return instance; 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 4/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 4/Program.cs: -------------------------------------------------------------------------------- 1 | namespace K_JonSkeet_4 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 4/Singleton.cs: -------------------------------------------------------------------------------- 1 | // Source: csharpindepth.com/Articles/General/Singleton.aspx 2 | // Fourth version - not quite as lazy, but thread-safe without using locks 3 | namespace K_JonSkeet_4 4 | { 5 | public sealed class Singleton 6 | { 7 | private static readonly Singleton instance = new Singleton(); 8 | // Explicit static constructor to tell C# compiler 9 | // not to mark type as beforefieldinit 10 | static Singleton() 11 | { 12 | } 13 | private Singleton() 14 | { 15 | } 16 | public static Singleton Instance 17 | { 18 | get 19 | { 20 | return instance; 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 5/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 5/Program.cs: -------------------------------------------------------------------------------- 1 | namespace K_JonSkeet_5 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 5/Singleton.cs: -------------------------------------------------------------------------------- 1 | // Source: csharpindepth.com/Articles/General/Singleton.aspx 2 | // Fifth version - fully lazy instantiation 3 | namespace K_JonSkeet_5 4 | { 5 | public sealed class Singleton 6 | { 7 | private Singleton() 8 | { 9 | } 10 | public static Singleton Instance { get { return Nested.instance; } } 11 | private class Nested 12 | { 13 | // Explicit static constructor to tell C# compiler 14 | // not to mark type as beforefieldinit 15 | static Nested() 16 | { 17 | } 18 | internal static readonly Singleton instance = new Singleton(); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 6/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 6/Program.cs: -------------------------------------------------------------------------------- 1 | namespace K_JonSkeet_6 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K JonSkeet 6/Singleton.cs: -------------------------------------------------------------------------------- 1 | // Source: csharpindepth.com/Articles/General/Singleton.aspx 2 | // Sixth version - using .NET 4's Lazy type 3 | using System; 4 | namespace K_JonSkeet_6 5 | { 6 | public sealed class Singleton 7 | { 8 | private static readonly Lazy lazy = 9 | new Lazy(() => new Singleton()); 10 | public static Singleton Instance { get { return lazy.Value; } } 11 | private Singleton() 12 | { 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /K-Singleton Pattern/K Solution 1/Account.cs: -------------------------------------------------------------------------------- 1 | namespace K_Solution_1 2 | { 3 | public class Account 4 | { 5 | private int id; 6 | private string name; 7 | private string type; 8 | private float balance; 9 | 10 | public Account(int id, string name, string type, float balance) 11 | { 12 | this.id = id; 13 | this.name = name; 14 | this.type = type; 15 | this.balance = balance; 16 | } 17 | 18 | public override string ToString() 19 | { 20 | return "Account [id=" + id + ", name=" + name + ", type=" + type + ", balance=" + balance + "]"; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /K-Singleton Pattern/K Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K Solution 1/Bank.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace K_Solution_1 4 | { 5 | public class Bank 6 | { 7 | public static Bank instance; 8 | private List accounts; 9 | 10 | private Bank() 11 | { 12 | accounts = new List(); 13 | } 14 | 15 | public static Bank getInstance() 16 | { 17 | if (instance == null) 18 | instance = new Bank(); 19 | return instance; 20 | } 21 | 22 | public void addAccount(Account account) 23 | { 24 | accounts.Add(account); 25 | } 26 | 27 | public void display() 28 | { 29 | accounts.ForEach(acc => 30 | { 31 | System.Console.WriteLine(acc); 32 | }); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /K-Singleton Pattern/K-Singleton Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /K-Singleton Pattern/K-Singleton Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace K_Singleton_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 1/CacheFactory.cs: -------------------------------------------------------------------------------- 1 | namespace L_Solution_1 2 | { 3 | public class CacheFactory 4 | { 5 | public static ICache getCache(int n) 6 | { 7 | if (n < 200) 8 | return new DefaultCache(n, "pol"); 9 | if (n < 1000) 10 | return new JCache(n, "fifo", true); 11 | return new TrieCache(n, "lfu", "tst"); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 1/DefaultCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static System.Console; 3 | using System.Collections.Generic; 4 | 5 | namespace L_Solution_1 6 | { 7 | public class DefaultCache : ICache 8 | { 9 | private int size; 10 | private string policy; 11 | private Dictionary cache; 12 | 13 | public DefaultCache(int n, string policy) 14 | { 15 | size = n; 16 | this.policy = policy; 17 | cache = new Dictionary(); 18 | } 19 | 20 | public int get(string key) 21 | { 22 | WriteLine("Returning value from default cache"); 23 | return new Random().Next(100); 24 | } 25 | 26 | public void put(string key, int value) 27 | { 28 | WriteLine("inserting key-value inside default cache"); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 1/ICache.cs: -------------------------------------------------------------------------------- 1 | namespace L_Solution_1 2 | { 3 | public interface ICache 4 | { 5 | void put(string key, int value); 6 | int get(string key); 7 | } 8 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 1/JCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using static System.Console; 4 | 5 | namespace L_Solution_1 6 | { 7 | public class JCache : ICache 8 | { 9 | private int size; 10 | private string policy; 11 | private bool isSerializable; 12 | private Dictionary cache; 13 | 14 | public JCache(int size, string policy, bool isSerializable) 15 | { 16 | this.size = size; 17 | this.policy = policy; 18 | this.isSerializable = isSerializable; 19 | cache = new Dictionary(); 20 | } 21 | 22 | public int get(string key) 23 | { 24 | WriteLine("Returning value from jcache"); 25 | return new Random().Next(100); 26 | } 27 | 28 | public void put(string key, int value) 29 | { 30 | WriteLine("inserting key-value inside jcache"); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace L_Solution_1 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | int n = Convert.ToInt32(Console.ReadLine()); 10 | 11 | ICache cache = CacheFactory.getCache(n); 12 | cache.put("abc", 100); 13 | cache.put("def", 2000); 14 | cache.put("xyz", 170); 15 | cache.get("abc"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 1/TrieCache.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | using System.Collections.Generic; 3 | using System; 4 | 5 | namespace L_Solution_1 6 | { 7 | public class TrieCache : ICache 8 | { 9 | private int size; 10 | private string policy; 11 | private string type; 12 | private Dictionary cache; 13 | 14 | public TrieCache(int size, string policy, string type) 15 | { 16 | this.size = size; 17 | this.policy = policy; 18 | this.type = type; 19 | cache = new Dictionary(); 20 | } 21 | 22 | public int get(string key) 23 | { 24 | WriteLine("Returning value from trie cache"); 25 | return new Random().Next(100); 26 | } 27 | 28 | public void put(string key, int value) 29 | { 30 | WriteLine("inserting key-value inside trie cache"); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 2/CacheFactory.cs: -------------------------------------------------------------------------------- 1 | namespace L_Solution_2 2 | { 3 | public class CacheFactory : ICacheFactory 4 | { 5 | public ICache getCache(int n) 6 | { 7 | if (n < 200) 8 | return new DefaultCache(n, "lru"); 9 | if (n < 1000) 10 | return new JCache(n, "fifo", true); 11 | return new TrieCache(n, "lfu", "tst"); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 2/DefaultCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using static System.Console; 4 | 5 | namespace L_Solution_2 6 | { 7 | public class DefaultCache : ICache 8 | { 9 | private int size; 10 | private string policy; 11 | private Dictionary cache; 12 | 13 | public DefaultCache(int n, string policy) 14 | { 15 | size = n; 16 | this.policy = policy; 17 | cache = new Dictionary(); 18 | } 19 | 20 | public int get(string key) 21 | { 22 | WriteLine("Returning value from default cache"); 23 | return new Random().Next(1000); 24 | } 25 | 26 | public void put(string key, int value) 27 | { 28 | WriteLine("inserting key-value inside default cache"); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 2/ICache.cs: -------------------------------------------------------------------------------- 1 | namespace L_Solution_2 2 | { 3 | public interface ICache 4 | { 5 | void put(string key, int value); 6 | int get(string key); 7 | } 8 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 2/ICacheFactory.cs: -------------------------------------------------------------------------------- 1 | namespace L_Solution_2 2 | { 3 | public interface ICacheFactory 4 | { 5 | ICache getCache(int n); 6 | } 7 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 2/JCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static System.Console; 3 | using System.Collections.Generic; 4 | 5 | namespace L_Solution_2 6 | { 7 | public class JCache : ICache 8 | { 9 | private int size; 10 | private string policy; 11 | private bool isSerializable; 12 | private Dictionary cache; 13 | 14 | public JCache(int size, string policy, bool isSerializable) 15 | { 16 | this.size = size; 17 | this.policy = policy; 18 | this.isSerializable = isSerializable; 19 | cache = new Dictionary(); 20 | } 21 | 22 | public int get(string key) 23 | { 24 | WriteLine("Returning value from jcache"); 25 | return new Random().Next(100); 26 | } 27 | 28 | public void put(string key, int value) 29 | { 30 | WriteLine("inserting key-value inside jcache"); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace L_Solution_2 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | int n = Convert.ToInt32(Console.ReadLine()); 10 | 11 | ICacheFactory cacheFactory = new CacheFactory(); 12 | ICache cache = cacheFactory.getCache(n); 13 | 14 | cache.put("abc", 100); 15 | cache.put("def", 2000); 16 | cache.put("xyz", 170); 17 | cache.get("abc"); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L Solution 2/TrieCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static System.Console; 3 | using System.Collections.Generic; 4 | 5 | namespace L_Solution_2 6 | { 7 | public class TrieCache : ICache 8 | { 9 | private int size; 10 | private string policy; 11 | private string type; 12 | private Dictionary cache; 13 | 14 | public TrieCache(int size, string policy, string type) 15 | { 16 | this.size = size; 17 | this.policy = policy; 18 | this.type = type; 19 | cache = new Dictionary(); 20 | } 21 | 22 | public int get(string key) 23 | { 24 | WriteLine("Returning value from trie cache"); 25 | return new Random().Next(100); 26 | } 27 | 28 | public void put(string key, int value) 29 | { 30 | WriteLine("inserting key-value inside trie cache"); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /L-Factory Method Pattern/L-Factory Method Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /L-Factory Method Pattern/L-Factory Method Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace L_Factory_Method_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/AudiCar.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public class AudiCar 4 | { 5 | private IGearBox gearBox; 6 | private IWheel wheels; 7 | private IStereo stereo; 8 | 9 | public void setGearBox(IGearBox gearBox) 10 | { 11 | this.gearBox = gearBox; 12 | } 13 | 14 | public void setWheels(IWheel wheels) 15 | { 16 | this.wheels = wheels; 17 | } 18 | 19 | public void setStereo(IStereo stereo) 20 | { 21 | this.stereo = stereo; 22 | } 23 | 24 | public override string ToString() 25 | { 26 | return "AudiCar [gearBox=" + gearBox + ", wheels=" + wheels + ", stereo=" + stereo + "]"; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/EGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public class EGearBox : IGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "economy gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/EStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public class EStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "economy stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/EWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public class EWheel : IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "economy wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/IGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public interface IGearBox 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/IStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public interface IStereo 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/IWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public interface IWheel 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/LGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public class LGearBox : IGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/LStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public class LStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/LWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public class LWheel : IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/MGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public class MGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "medium gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/MStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public class MStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "medium stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/MWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | public class MWheel:IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "medium wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_1 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | AudiCar eCar = new AudiCar(); 8 | eCar.setGearBox(new EGearBox()); 9 | eCar.setStereo(new EStereo()); 10 | eCar.setWheels(new EWheel()); 11 | System.Console.WriteLine(eCar); 12 | 13 | AudiCar xCar = new AudiCar(); 14 | xCar.setGearBox(new EGearBox()); 15 | xCar.setStereo(new MStereo()); 16 | xCar.setWheels(new LWheel()); 17 | System.Console.WriteLine(xCar); 18 | } 19 | } 20 | } 21 | 22 | //Problem: any level of part can be assigned to any car object -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/AudiCar.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class AudiCar 4 | { 5 | private IGearBox gearBox; 6 | private IWheel wheels; 7 | private IStereo stereo; 8 | 9 | public void setGearBox(IGearBox gearBox) 10 | { 11 | this.gearBox = gearBox; 12 | } 13 | 14 | public void setWheels(IWheel wheels) 15 | { 16 | this.wheels = wheels; 17 | } 18 | 19 | public void setStereo(IStereo stereo) 20 | { 21 | this.stereo = stereo; 22 | } 23 | 24 | public override string ToString() 25 | { 26 | return "AudiCar [gearBox=" + gearBox + ", wheels=" + wheels + ", stereo=" + stereo + "]"; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/EGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class EGearBox : IGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "economy gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/EStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class EStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "economy stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/EWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class EWheel : IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "economy wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/EconomyAudiBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class EconomyAudiBuilder 4 | { 5 | public static AudiCar getCar() 6 | { 7 | AudiCar eCar = new AudiCar(); 8 | eCar.setGearBox(new EGearBox()); 9 | eCar.setStereo(new EStereo()); 10 | eCar.setWheels(new EWheel()); 11 | return eCar; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/IGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public interface IGearBox 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/IStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public interface IStereo 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/IWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public interface IWheel 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/LGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class LGearBox : IGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/LStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class LStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/LWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class LWheel : IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/LuxuryAudiBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class LuxuryAudiBuilder 4 | { 5 | public static AudiCar getCar() 6 | { 7 | AudiCar lCar = new AudiCar(); 8 | lCar.setGearBox(new LGearBox()); 9 | lCar.setStereo(new LStereo()); 10 | lCar.setWheels(new LWheel()); 11 | return lCar; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/MGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class MGearBox : IGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "medium gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/MStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class MStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "medium stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/MWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class MWheel : IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "medium wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/MediumAudiBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | public class MediumAudiBuilder 4 | { 5 | public static AudiCar getCar() 6 | { 7 | AudiCar mCar = new AudiCar(); 8 | mCar.setGearBox(new MGearBox()); 9 | mCar.setStereo(new MStereo()); 10 | mCar.setWheels(new MWheel()); 11 | return mCar; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 2/Program.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_2 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | AudiCar eCar = EconomyAudiBuilder.getCar(); 8 | System.Console.WriteLine(eCar); 9 | 10 | AudiCar mCar = MediumAudiBuilder.getCar(); 11 | System.Console.WriteLine(mCar); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/AbstractAudiBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public abstract class AbstractAudiBuilder 4 | { 5 | public abstract IGearBox getGearBox(); 6 | public abstract IWheel getWheel(); 7 | public abstract IStereo getStereo(); 8 | 9 | public AudiCar getCar() 10 | { 11 | AudiCar audiCar = new AudiCar(); 12 | audiCar.setGearBox(getGearBox()); 13 | audiCar.setStereo(getStereo()); 14 | audiCar.setWheels(getWheel()); 15 | return audiCar; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/AudiCar.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class AudiCar 4 | { 5 | private IGearBox gearBox; 6 | private IWheel wheels; 7 | private IStereo stereo; 8 | 9 | public void setGearBox(IGearBox gearBox) 10 | { 11 | this.gearBox = gearBox; 12 | } 13 | 14 | public void setWheels(IWheel wheels) 15 | { 16 | this.wheels = wheels; 17 | } 18 | 19 | public void setStereo(IStereo stereo) 20 | { 21 | this.stereo = stereo; 22 | } 23 | 24 | public override string ToString() 25 | { 26 | return "AudiCar [gearBox=" + gearBox + ", wheels=" + wheels + ", stereo=" + stereo + "]"; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/EGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class EGearBox : IGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "economy gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/EStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class EStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "economy stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/EWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class EWheel : IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "economy wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/EconomyAudiBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class EconomyAudiBuilder:AbstractAudiBuilder 4 | { 5 | public override IGearBox getGearBox() 6 | { 7 | return new EGearBox(); 8 | } 9 | 10 | public override IWheel getWheel() 11 | { 12 | return new EWheel(); 13 | } 14 | 15 | public override IStereo getStereo() 16 | { 17 | return new EStereo(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/IGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public interface IGearBox 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/IStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public interface IStereo 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/IWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public interface IWheel 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/LGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class LGearBox : IGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/LStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class LStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/LWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class LWheel : IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/LuxuryAudiBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class LuxuryAudiBuilder:AbstractAudiBuilder 4 | { 5 | public override IGearBox getGearBox() 6 | { 7 | return new LGearBox(); 8 | } 9 | 10 | public override IWheel getWheel() 11 | { 12 | return new LWheel(); 13 | } 14 | 15 | public override IStereo getStereo() 16 | { 17 | return new LStereo(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/MGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class MGearBox : IGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "medium gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/MStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class MStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "medium stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/MWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | public class MWheel : IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "medium wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/MediumAudiBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace M_Solution_3 4 | { 5 | public class MediumAudiBuilder : AbstractAudiBuilder 6 | { 7 | public override IGearBox getGearBox() 8 | { 9 | return new MGearBox(); 10 | } 11 | 12 | public override IWheel getWheel() 13 | { 14 | return new MWheel(); 15 | } 16 | 17 | public override IStereo getStereo() 18 | { 19 | return new MStereo(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 3/Program.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_3 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | AbstractAudiBuilder builder = new EconomyAudiBuilder(); 8 | AudiCar car1 = builder.getCar(); 9 | System.Console.WriteLine(car1); 10 | 11 | builder = new MediumAudiBuilder(); 12 | AudiCar car2 = builder.getCar(); 13 | System.Console.WriteLine(car2); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/AudiCar.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class AudiCar 4 | { 5 | private IGearBox gearBox; 6 | private IWheel wheels; 7 | private IStereo stereo; 8 | 9 | public void setGearBox(IGearBox gearBox) 10 | { 11 | this.gearBox = gearBox; 12 | } 13 | 14 | public void setWheels(IWheel wheels) 15 | { 16 | this.wheels = wheels; 17 | } 18 | 19 | public void setStereo(IStereo stereo) 20 | { 21 | this.stereo = stereo; 22 | } 23 | 24 | public override string ToString() 25 | { 26 | return "AudiCar [gearBox=" + gearBox + ", wheels=" + wheels + ", stereo=" + stereo + "]"; 27 | } 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/EGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class EGearBox : IGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "economy gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/EStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class EStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "economy stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/EWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class EWheel : IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "economy wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/EconomyCarFactory.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class EconomyCarFactory : ICarFactory 4 | { 5 | public IGearBox getGearBox() 6 | { 7 | return new EGearBox(); 8 | } 9 | 10 | public IStereo getStereo() 11 | { 12 | return new EStereo(); 13 | } 14 | 15 | public IWheel getWheel() 16 | { 17 | return new EWheel(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/ICarFactory.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public interface ICarFactory 4 | { 5 | IGearBox getGearBox(); 6 | IStereo getStereo(); 7 | IWheel getWheel(); 8 | } 9 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/IGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public interface IGearBox 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/IStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public interface IStereo 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/IWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public interface IWheel 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/LGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class LGearBox : IGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/LStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class LStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/LWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class LWheel : IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "luxury wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/LuxuryCarFactory.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class LuxuryCarFactory : ICarFactory 4 | { 5 | public IGearBox getGearBox() 6 | { 7 | return new LGearBox(); 8 | } 9 | 10 | public IStereo getStereo() 11 | { 12 | return new LStereo(); 13 | } 14 | 15 | public IWheel getWheel() 16 | { 17 | return new LWheel(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/MGearBox.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class MGearBox : IGearBox 4 | { 5 | public override string ToString() 6 | { 7 | return "medium gear box"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/MStereo.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class MStereo : IStereo 4 | { 5 | public override string ToString() 6 | { 7 | return "medium stereo"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/MWheel.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class MWheel : IWheel 4 | { 5 | public override string ToString() 6 | { 7 | return "medium wheels"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/MediumCarFactory.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | public class MediumCarFactory : ICarFactory 4 | { 5 | public IGearBox getGearBox() 6 | { 7 | return new MGearBox(); 8 | } 9 | 10 | public IStereo getStereo() 11 | { 12 | return new MStereo(); 13 | } 14 | 15 | public IWheel getWheel() 16 | { 17 | return new MWheel(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M Solution 4/Program.cs: -------------------------------------------------------------------------------- 1 | namespace M_Solution_4 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | ICarFactory factory = new EconomyCarFactory(); 8 | AudiCar car1 = new AudiCar(); 9 | car1.setGearBox(factory.getGearBox()); 10 | car1.setStereo(factory.getStereo()); 11 | car1.setWheels(factory.getWheel()); 12 | System.Console.WriteLine(car1); 13 | 14 | factory = new MediumCarFactory(); 15 | AudiCar car2 = new AudiCar(); 16 | car2.setGearBox(factory.getGearBox()); 17 | car2.setStereo(factory.getStereo()); 18 | car2.setWheels(factory.getWheel()); 19 | System.Console.WriteLine(car2); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M-AbstractFactory And Builder Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /M-AbstractFactory And Builder Pattern/M-AbstractFactory And Builder Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | namespace M_AbstractFactory_And_Builder_Pattern 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /N-Composite Pattern/N Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /N-Composite Pattern/N Solution 1/File.cs: -------------------------------------------------------------------------------- 1 | namespace N_Solution_1 2 | { 3 | public class File 4 | { 5 | private string name; 6 | private Directory parent; 7 | 8 | public File(Directory parent, string name) 9 | { 10 | this.name = name; 11 | this.parent = parent; 12 | parent.add(this); 13 | } 14 | 15 | public override string ToString() 16 | { 17 | return "File [name=" + name + ", parent=" + parent + "]"; 18 | } 19 | 20 | public string getName() 21 | { 22 | return name; 23 | } 24 | 25 | // public string getAbsolutePath() { } 26 | } 27 | } -------------------------------------------------------------------------------- /N-Composite Pattern/N Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /N-Composite Pattern/N Solution 2/File.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace N_Solution_2 4 | { 5 | public class File : Node 6 | { 7 | public File(Directory parent, string name) : base(parent, name) 8 | { 9 | parent.add(this); 10 | } 11 | 12 | public override void find(string pattern) 13 | { 14 | if (name.IndexOf(pattern) != -1) 15 | WriteLine(this); 16 | } 17 | 18 | public override void traverse() 19 | { 20 | WriteLine(this); 21 | } 22 | 23 | public override string ToString() 24 | { 25 | return "File [name=" + name + ", parent=" + parent + "]"; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /N-Composite Pattern/N Solution 2/Node.cs: -------------------------------------------------------------------------------- 1 | namespace N_Solution_2 2 | { 3 | public abstract class Node 4 | { 5 | protected string name; 6 | protected Directory parent; 7 | 8 | public Node(Directory parent, string name) 9 | { 10 | this.name = name; 11 | this.parent = parent; 12 | } 13 | 14 | public abstract void traverse(); 15 | public abstract void find(string pattern); 16 | } 17 | } -------------------------------------------------------------------------------- /N-Composite Pattern/N Solution 2/Program.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | 3 | namespace N_Solution_2 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Directory root = new Directory("/"); 10 | Directory home = new Directory(root, "/home"); 11 | Directory bin = new Directory(root, "/bin"); 12 | 13 | File file1 = new File(home, "file1.txt"); 14 | File file2 = new File(bin, "file2.bin"); 15 | Directory user1 = new Directory(home, "/user1"); 16 | 17 | root.traverse(); 18 | WriteLine(); 19 | home.traverse(); 20 | WriteLine(); 21 | bin.traverse(); 22 | WriteLine(); 23 | root.find("file1"); 24 | WriteLine(); 25 | bin.find("file1"); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /N-Composite Pattern/N-Composite Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /N-Composite Pattern/N-Composite Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace N_Composite_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /O-Chain Of Responsibility Pattern/O Solution 1/AbstractHandler.cs: -------------------------------------------------------------------------------- 1 | namespace O_Solution_1 2 | { 3 | public abstract class AbstractHandler 4 | { 5 | private string name; 6 | private string role; 7 | 8 | public AbstractHandler(string name, string role) 9 | { 10 | this.name = name; 11 | this.role = role; 12 | } 13 | 14 | public override string ToString() 15 | { 16 | return "AbstractRole [name=" + name + ", role=" + role + "]"; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /O-Chain Of Responsibility Pattern/O Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /O-Chain Of Responsibility Pattern/O Solution 1/CEO.cs: -------------------------------------------------------------------------------- 1 | namespace O_Solution_1 2 | { 3 | public class CEO : AbstractHandler 4 | { 5 | public CEO(string name) : base(name, "CEO") { } 6 | 7 | public bool approve(PurchaseOrder po) 8 | { 9 | if (po.getAmount() < 50000) 10 | { 11 | System.Console.WriteLine("approved by " + ToString()); 12 | return true; 13 | } 14 | else return false; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /O-Chain Of Responsibility Pattern/O Solution 1/Director.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace O_Solution_1 8 | { 9 | class Director 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /O-Chain Of Responsibility Pattern/O Solution 1/ExecutiveCommittee.cs: -------------------------------------------------------------------------------- 1 | namespace O_Solution_1 2 | { 3 | public class ExecutiveCommittee : AbstractHandler 4 | { 5 | public ExecutiveCommittee(string name) : base(name, "Executive Committee") { } 6 | 7 | public bool approve(PurchaseOrder po) 8 | { 9 | System.Console.WriteLine("approved by " + ToString()); 10 | return true; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /O-Chain Of Responsibility Pattern/O Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace O_Solution_1 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /O-Chain Of Responsibility Pattern/O Solution 1/PurchaseOrder.cs: -------------------------------------------------------------------------------- 1 | namespace O_Solution_1 2 | { 3 | public class PurchaseOrder 4 | { 5 | private float amount; 6 | private int id; 7 | private string description; 8 | 9 | public float getAmount() 10 | { 11 | return amount; 12 | } 13 | 14 | public void setAmount(float amount) 15 | { 16 | this.amount = amount; 17 | } 18 | 19 | public int getId() 20 | { 21 | return id; 22 | } 23 | 24 | public int setId(int id) 25 | { 26 | return id; 27 | } 28 | 29 | public string getDescription() 30 | { 31 | return description; 32 | } 33 | 34 | public void setDescription(string description) 35 | { 36 | this.description = description; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /O-Chain Of Responsibility Pattern/O Solution 1/SeniorManager.cs: -------------------------------------------------------------------------------- 1 | namespace O_Solution_1 2 | { 3 | public class SeniorManager : AbstractHandler 4 | { 5 | public SeniorManager(string name) : base(name, "Senior Manager") { } 6 | 7 | public bool approve(PurchaseOrder po) 8 | { 9 | if (po.getAmount() < 1000) 10 | { 11 | System.Console.WriteLine("approved by " + ToString()); 12 | return true; 13 | } 14 | else return false; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /O-Chain Of Responsibility Pattern/O Solution 1/VP.cs: -------------------------------------------------------------------------------- 1 | namespace O_Solution_1 2 | { 3 | public class VP : AbstractHandler 4 | { 5 | public VP(string name) : base(name, "VP") { } 6 | 7 | public bool approve(PurchaseOrder po) 8 | { 9 | if (po.getAmount() < 10000) 10 | { 11 | System.Console.WriteLine("approved by " + ToString()); 12 | return true; 13 | } 14 | else return true; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /O-Chain Of Responsibility Pattern/O-Chain Of Responsibility Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /O-Chain Of Responsibility Pattern/O-Chain Of Responsibility Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace O_Chain_Of_Responsibility_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/BulletView.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | using System.Collections.Generic; 3 | 4 | namespace P_Solution_1 5 | { 6 | public class BulletView : IViewStrategy 7 | { 8 | public void formattedDisplay(List tasks) 9 | { 10 | foreach (var task in tasks) 11 | WriteLine("*" + tasks.ToString()); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/DueDateBasedSortStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace P_Solution_1 5 | { 6 | public class DueDateBasedSortStrategy : ISortStrategy 7 | { 8 | class DueDateComparator : Comparer 9 | { 10 | public override int Compare(Task x, Task y) 11 | { 12 | return x.getDuedate().CompareTo(y.getDuedate()); 13 | } 14 | } 15 | public void sort(List tasks) 16 | { 17 | tasks.Sort(new DueDateComparator()); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/ISortStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace P_Solution_1 4 | { 5 | public interface ISortStrategy 6 | { 7 | void sort(List tasks); 8 | } 9 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/IViewStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace P_Solution_1 4 | { 5 | public interface IViewStrategy 6 | { 7 | void formattedDisplay(List tasks); 8 | } 9 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/ListView.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | using System.Collections.Generic; 3 | 4 | namespace P_Solution_1 5 | { 6 | public class ListView : IViewStrategy 7 | { 8 | public void formattedDisplay(List tasks) 9 | { 10 | tasks.ForEach(task => { 11 | WriteLine("-" + task.ToString()); 12 | }); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/NumberedView.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | using System.Collections.Generic; 3 | 4 | namespace P_Solution_1 5 | { 6 | public class NumberedView : IViewStrategy 7 | { 8 | public void formattedDisplay(List tasks) 9 | { 10 | int n = 0; 11 | tasks.ForEach(task => 12 | { 13 | WriteLine(++n + task.ToString()); 14 | }); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/PriorityBasedSortStratrgy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace P_Solution_1 5 | { 6 | public class PriorityBasedSortStratrgy : ISortStrategy 7 | { 8 | class PriorityComparator : Comparer 9 | { 10 | public override int Compare(Task x, Task y) 11 | { 12 | return x.getPriority() - y.getPriority(); 13 | } 14 | } 15 | public void sort(List tasks) 16 | { 17 | tasks.Sort(new PriorityComparator()); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace P_Solution_1 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | ToDoList todolist = new ToDoList(); 10 | todolist.addTask(new Task("task1", new DateTime(), 3)); 11 | todolist.addTask(new Task("task2", new DateTime(), 2)); 12 | todolist.addTask(new Task("task3", new DateTime(), 4)); 13 | todolist.setSortStrategy(new PriorityBasedSortStratrgy()); 14 | todolist.setViewStrategy(new ListView()); 15 | todolist.display(); 16 | todolist.setViewStrategy(new NumberedView()); 17 | todolist.display(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/Task.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace P_Solution_1 4 | { 5 | public class Task 6 | { 7 | private string description; 8 | private DateTime duedate; 9 | private int priority; 10 | 11 | public Task(string description, DateTime duedate, int priority) 12 | { 13 | this.description = description; 14 | this.duedate = duedate; 15 | this.priority = priority; 16 | } 17 | 18 | public string getDescription() 19 | { 20 | return description; 21 | } 22 | 23 | public DateTime getDuedate() 24 | { 25 | return duedate; 26 | } 27 | 28 | public int getPriority() 29 | { 30 | return priority; 31 | } 32 | 33 | public override string ToString() 34 | { 35 | return "Task [description=" + description + ", duedate=" + duedate + ", priority=" + priority + "]"; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/ToDoList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace P_Solution_1 4 | { 5 | public class ToDoList 6 | { 7 | private List tasks; 8 | private ISortStrategy sortStrategy; 9 | private IViewStrategy viewStrategy; 10 | 11 | public ToDoList() 12 | { 13 | tasks = new List(); 14 | } 15 | 16 | public void addTask(Task task) 17 | { 18 | tasks.Add(task); 19 | } 20 | 21 | public void setSortStrategy(ISortStrategy sortStrategy) 22 | { 23 | this.sortStrategy = sortStrategy; 24 | } 25 | 26 | public void setViewStrategy(IViewStrategy viewStrategy) 27 | { 28 | this.viewStrategy = viewStrategy; 29 | } 30 | 31 | public void display() 32 | { 33 | sortStrategy.sort(tasks); 34 | viewStrategy.formattedDisplay(tasks); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 1/UnsortedStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Collections.Generic; 3 | using System; 4 | 5 | namespace P_Solution_1 6 | { 7 | public class UnsortedStrategy : ISortStrategy 8 | { 9 | public void sort(List tasks) 10 | { 11 | // Can be implemented any Shuffling logic here 12 | tasks.OrderBy(item => new Random().Next()); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/AbstractView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace P_Solution_2 4 | { 5 | public abstract class AbstractView 6 | { 7 | protected List tasks; 8 | private ISortStrategy sortStrategy; 9 | 10 | public AbstractView(List tasks) 11 | { 12 | this.tasks = tasks; 13 | sortStrategy = new UnsortedStrategy(); 14 | } 15 | 16 | public void setSortStrategy(ISortStrategy sortStrategy) { 17 | this.sortStrategy = sortStrategy; 18 | } 19 | 20 | public abstract void formattedDisplay(); 21 | 22 | public void display() 23 | { 24 | sortStrategy.sort(tasks); 25 | formattedDisplay(); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/BulletView.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | using System.Collections.Generic; 3 | 4 | namespace P_Solution_2 5 | { 6 | public class BulletView : AbstractView 7 | { 8 | public BulletView(List tasks) : base(tasks) { } 9 | 10 | public override void formattedDisplay() 11 | { 12 | tasks.ForEach(task => 13 | { 14 | WriteLine("*" + task.ToString()); 15 | }); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/DueDateBasedSortStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace P_Solution_2 4 | { 5 | public class DueDateBasedSortStrategy : ISortStrategy 6 | { 7 | class DueDateComparator : Comparer 8 | { 9 | public override int Compare(Task x, Task y) 10 | { 11 | return x.getDuedate().CompareTo(y.getDuedate()); 12 | } 13 | } 14 | 15 | public void sort(List tasks) 16 | { 17 | tasks.Sort(new DueDateComparator()); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/ISortStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace P_Solution_2 4 | { 5 | public interface ISortStrategy 6 | { 7 | void sort(List tasks); 8 | } 9 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/IViewStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace P_Solution_2 4 | { 5 | interface IViewStrategy 6 | { 7 | void formattedDisplay(List tasks); 8 | } 9 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/ListView.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | using System.Collections.Generic; 3 | 4 | namespace P_Solution_2 5 | { 6 | public class ListView : AbstractView 7 | { 8 | public ListView(List tasks) : base(tasks) { } 9 | 10 | public override void formattedDisplay() 11 | { 12 | tasks.ForEach(task => 13 | { 14 | WriteLine("-" + task.ToString()); 15 | }); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/NumberedView.cs: -------------------------------------------------------------------------------- 1 | using static System.Console; 2 | using System.Collections.Generic; 3 | 4 | namespace P_Solution_2 5 | { 6 | public class NumberedView : AbstractView 7 | { 8 | public NumberedView(List tasks) : base(tasks) { } 9 | 10 | public override void formattedDisplay() 11 | { 12 | int n = 0; 13 | tasks.ForEach(task => 14 | { 15 | WriteLine((++n) + task.ToString()); 16 | }); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/PriorityBasedSortStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace P_Solution_2 4 | { 5 | public class PriorityBasedSortStrategy : ISortStrategy 6 | { 7 | class PriorityComparator : Comparer 8 | { 9 | public override int Compare(Task x, Task y) 10 | { 11 | return x.getPriority() - y.getPriority(); 12 | } 13 | } 14 | 15 | public void sort(List tasks) 16 | { 17 | tasks.Sort(new PriorityComparator()); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace P_Solution_2 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | List tasks = new List(); 11 | tasks.Add(new Task("task1", new DateTime(), 3)); 12 | tasks.Add(new Task("task2", new DateTime(), 2)); 13 | tasks.Add(new Task("task3", new DateTime(), 4)); 14 | 15 | AbstractView todoList = new ListView(tasks); 16 | todoList.setSortStrategy(new PriorityBasedSortStrategy()); 17 | todoList.display(); 18 | todoList = new NumberedView(tasks); 19 | todoList.display(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/Task.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace P_Solution_2 4 | { 5 | public class Task 6 | { 7 | private string description; 8 | private DateTime duedate; 9 | private int priority; 10 | 11 | public Task(string description, DateTime duedate, int priority) 12 | { 13 | this.description = description; 14 | this.duedate = duedate; 15 | this.priority = priority; 16 | } 17 | 18 | public string getDescription() 19 | { 20 | return description; 21 | } 22 | 23 | public DateTime getDuedate() 24 | { 25 | return duedate; 26 | } 27 | 28 | public int getPriority() 29 | { 30 | return priority; 31 | } 32 | 33 | public override string ToString() 34 | { 35 | return "Task [description=" + description + ", duedate=" + duedate + ", priority=" + priority + "]"; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P Solution 2/UnsortedStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace P_Solution_2 4 | { 5 | public class UnsortedStrategy : ISortStrategy 6 | { 7 | public void sort(List tasks) 8 | { 9 | // Shuffle Logic Here 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /P-Bridge Pattern/P-Bridge Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /P-Bridge Pattern/P-Bridge Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P_Bridge_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Patterns/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Patterns/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Patterns 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 1/Address.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_1 2 | { 3 | public class Address 4 | { 5 | private string houseno; 6 | private string landmark; 7 | private string state; 8 | private string area; 9 | 10 | public Address(string houseno, string landmark, string state, string area) 11 | { 12 | this.houseno = houseno; 13 | this.landmark = landmark; 14 | this.state = state; 15 | this.area = area; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 1/DBInventoryService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_1 2 | { 3 | public class DBInventoryService : IInventoryService 4 | { 5 | public bool checkStock(Product product) 6 | { 7 | return new System.Random().Next(5) > 5 ? true : false; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 1/FedExShippingService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_1 2 | { 3 | public class FedExShippingService : IShippingService 4 | { 5 | public bool ship(Product product, Address address) 6 | { 7 | return new System.Random().Next(5) > 5 ? true : false; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 1/ICICIPaymentService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_1 2 | { 3 | public class ICICIPaymentService : IPaymentService 4 | { 5 | public bool pay(float amount, int cardno, int cvv) 6 | { 7 | return new System.Random().Next(5) > 5 ? true : false; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 1/IInventoryService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_1 2 | { 3 | public interface IInventoryService 4 | { 5 | bool checkStock(Product product); 6 | } 7 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 1/IPaymentService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_1 2 | { 3 | public interface IPaymentService 4 | { 5 | bool pay(float amount, int cardno, int cvv); 6 | } 7 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 1/IShippingService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_1 2 | { 3 | public interface IShippingService 4 | { 5 | bool ship(Product product, Address address); 6 | } 7 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 1/PayPalPaymentService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_1 2 | { 3 | public class PayPalPaymentService : IPaymentService 4 | { 5 | public bool pay(float amount, int cardno, int cvv) 6 | { 7 | return new System.Random().Next(5) > 5 ? true : false; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 1/Product.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_1 2 | { 3 | public class Product 4 | { 5 | private string id; 6 | private string description; 7 | public Product(string id, string description) 8 | { 9 | this.id = id; 10 | this.description = description; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_1 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | Product product1 = new Product("12345", "laptop-dell"); 8 | MobileController order1 = new MobileController( 9 | new DBInventoryService(), 10 | new ICICIPaymentService(), 11 | new FedExShippingService()); 12 | order1.orderProduct( 13 | product1, 120, 2345, 112, 14 | new Address("1-1", "", "", "")); 15 | 16 | Product product2 = new Product("12346", "mobile-oppo"); 17 | DesktopController order2 = new DesktopController( 18 | new DBInventoryService(), 19 | new PayPalPaymentService(), 20 | new FedExShippingService()); 21 | order2.orderProduct(product2, 120, 2341, 111, 22 | new Address("1-2", "", "", "")); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/Address.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public class Address 4 | { 5 | private string houseno; 6 | private string landmark; 7 | private string state; 8 | private string area; 9 | 10 | public Address(string houseno, string landmark, string state, string area) 11 | { 12 | this.houseno = houseno; 13 | this.landmark = landmark; 14 | this.state = state; 15 | this.area = area; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/DBInventoryService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public class DBInventoryService : IInventoryService 4 | { 5 | public bool checkStock(Product product) 6 | { 7 | return new System.Random().Next(5) > 0.4 ? true : false; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/DesktopController.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public class DesktopController 4 | { 5 | private IOrderFacade orderFacade; 6 | 7 | public DesktopController(IOrderFacade orderFacade) 8 | { 9 | this.orderFacade = orderFacade; 10 | } 11 | 12 | public void orderProduct(Product product, float amount, int cardno, int cvv, Address address) 13 | { 14 | orderFacade.orderProduct(product, amount, cardno, cvv, address); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/FedExShippingService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public class FedExShippingService : IShippingService 4 | { 5 | public bool ship(Product product, Address address) 6 | { 7 | return new System.Random().Next(5) > 5 ? true : false; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/ICICIPaymentService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public class ICICIPaymentService : IPaymentService 4 | { 5 | public bool pay(float amount, int cardno, int cvv) 6 | { 7 | return new System.Random().Next(5) > 5 ? true : false; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/IInventoryService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public interface IInventoryService 4 | { 5 | bool checkStock(Product product); 6 | } 7 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/IOrderFacade.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public interface IOrderFacade 4 | { 5 | void orderProduct(Product product, float amount, int cardno, int cvv, Address address); 6 | } 7 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/IPaymentService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public interface IPaymentService 4 | { 5 | bool pay(float amount, int cardno, int cvv); 6 | } 7 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/IShippingService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public interface IShippingService 4 | { 5 | bool ship(Product product, Address address); 6 | } 7 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/MobileController.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public class MobileController 4 | { 5 | private IOrderFacade orderFacade; 6 | 7 | public MobileController(IOrderFacade orderFacade) 8 | { 9 | this.orderFacade = orderFacade; 10 | } 11 | 12 | public void orderProduct(Product product, float amount, int cardno, int cvv, Address address) 13 | { 14 | orderFacade.orderProduct(product, amount, cardno, cvv, address); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/PayPalPaymentService.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public class PayPalPaymentService : IPaymentService 4 | { 5 | public bool pay(float amount, int cardno, int cvv) 6 | { 7 | return new System.Random().Next(5) > 0.5 ? true : false; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q Solution 2/Product.cs: -------------------------------------------------------------------------------- 1 | namespace Q_Solution_2 2 | { 3 | public class Product 4 | { 5 | private string id; 6 | private string description; 7 | 8 | public Product(string id, string description) 9 | { 10 | this.id = id; 11 | this.description = description; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Q-Facade Pattern/Q-Facade Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q-Facade Pattern/Q-Facade Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Q_Facade_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /R-Proxy Pattern/R Solution 1/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /R-Proxy Pattern/R Solution 1/Document.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Windows.Forms; 3 | 4 | namespace R_Solution_1 5 | { 6 | public class Document 7 | { 8 | private string text_; 9 | private List images_; 10 | 11 | public Document() 12 | { 13 | images_ = new List(); 14 | } 15 | 16 | public void addText(string text) 17 | { 18 | text_ += text; 19 | } 20 | 21 | public void addImage(string path, string name) 22 | { 23 | images_.Add(new MyImage(path, name)); 24 | } 25 | 26 | public void open() 27 | { 28 | System.Console.WriteLine(text_); 29 | images_.ForEach(img => 30 | { 31 | Form form = new Form(); 32 | Label label = new Label(); 33 | form.BackgroundImage = img.getImage(); 34 | form.Show(); 35 | }); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /R-Proxy Pattern/R Solution 1/MyImage.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | 3 | namespace R_Solution_1 4 | { 5 | public class MyImage 6 | { 7 | private string path; 8 | private string name; 9 | 10 | public MyImage(string path, string name) 11 | { 12 | this.path = path; 13 | this.name = name; 14 | } 15 | 16 | public Image getImage() 17 | { 18 | Image image = Image.FromFile(path); 19 | return image; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /R-Proxy Pattern/R Solution 1/Program.cs: -------------------------------------------------------------------------------- 1 | namespace R_Solution_1 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | Document document = new Document(); 8 | document.addText("understanding the cost with disk reads"); 9 | document.addImage("1.jpg", "One"); 10 | document.addImage("2.jpg", "Two"); 11 | document.open(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /R-Proxy Pattern/R Solution 2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /R-Proxy Pattern/R Solution 2/IProxy.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | 3 | namespace R_Solution_2 4 | { 5 | public interface IProxy 6 | { 7 | Image getImage(); 8 | string getAlter(); 9 | } 10 | } -------------------------------------------------------------------------------- /R-Proxy Pattern/R Solution 2/MyImage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | 4 | namespace R_Solution_2 5 | { 6 | public class MyImage : IProxy 7 | { 8 | private string path; 9 | private string name; 10 | 11 | public MyImage(string path, string name) 12 | { 13 | this.path = path; 14 | this.name = name; 15 | } 16 | 17 | public string getAlter() 18 | { 19 | return name; 20 | } 21 | 22 | public Image getImage() 23 | { 24 | Image image = Image.FromFile(path); 25 | return image; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /R-Proxy Pattern/R Solution 2/MyImageProxy.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | 3 | namespace R_Solution_2 4 | { 5 | public class MyImageProxy : IProxy 6 | { 7 | public MyImage image_; 8 | 9 | public MyImageProxy(string path, string name) 10 | { 11 | image_ = new MyImage(path, name); 12 | } 13 | 14 | public string getAlter() 15 | { 16 | return image_.getAlter(); 17 | } 18 | 19 | public Image getImage() 20 | { 21 | return image_.getImage(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /R-Proxy Pattern/R Solution 2/Program.cs: -------------------------------------------------------------------------------- 1 | namespace R_Solution_2 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | Document document = new Document(); 8 | document.addText("understanding the cost with disk reads"); 9 | document.addImage("1.jpg", "One"); 10 | document.addImage("2.jpg", "Two"); 11 | document.open(); 12 | document.clickImage(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /R-Proxy Pattern/R-Proxy Pattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /R-Proxy Pattern/R-Proxy Pattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace R_Proxy_Pattern 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Design Patterns by Example 2 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | remote_theme: AshV/my-site-theme 2 | plugins: 3 | - jekyll-feed 4 | --------------------------------------------------------------------------------