├── .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