├── StrategyPattern
├── IFlyBehaviour.cs
├── IQuackBehaviour.cs
├── App.config
├── FlyNope.cs
├── FlyWings.cs
├── QuackNope.cs
├── QuackSqueak.cs
├── QuackNormal.cs
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── StrategyPattern.csproj
├── AdapterPattern
├── IDuck.cs
├── ITurkey.cs
├── App.config
├── Program.cs
├── MallardDuck.cs
├── WildTurkey.cs
├── TurkeyAdapter.cs
├── Properties
│ └── AssemblyInfo.cs
└── AdapterPattern.csproj
├── CommandPattern
├── ICommand.cs
├── OnOffStruct.cs
├── App.config
├── NoCommand.cs
├── LightOnCommand.cs
├── LightOffCommand.cs
├── GarageDoorOpenCommand.cs
├── GarageDoorCloseCommand.cs
├── Light.cs
├── Garage.cs
├── MacroCommand.cs
├── RemoteControl.cs
├── Properties
│ └── AssemblyInfo.cs
├── Program.cs
└── CommandPattern.csproj
├── StatePattern
├── Legacy
│ ├── State.cs
│ └── GumballMachine.cs
├── App.config
├── IState.cs
├── Program.cs
├── SoldOutState.cs
├── NoQuarterState.cs
├── SoldState.cs
├── HasQuarterState.cs
├── WinnerState.cs
├── GumballMachine.cs
├── Properties
│ └── AssemblyInfo.cs
└── StatePattern.csproj
├── FactoryPattern
├── Abstract Factory
│ ├── Ingredients
│ │ ├── Intefaces
│ │ │ ├── IClam.cs
│ │ │ ├── ICheese.cs
│ │ │ ├── IDough.cs
│ │ │ ├── ISauce.cs
│ │ │ └── IVeggies.cs
│ │ ├── Olive.cs
│ │ ├── Cucumber.cs
│ │ ├── DeepDish.cs
│ │ ├── FreshClam.cs
│ │ ├── Mozarella.cs
│ │ ├── Parmesan.cs
│ │ ├── ThinCrust.cs
│ │ ├── FrozenClam.cs
│ │ ├── Pepper.cs
│ │ ├── PlumTomato.cs
│ │ ├── CherryTomato.cs
│ │ └── Onion.cs
│ ├── IIngredientsFactory.cs
│ ├── NYIngredientsFactory.cs
│ └── ChicagoIngredientsFactory.cs
├── App.config
├── Factory Method
│ ├── PizzaFactory.cs
│ ├── NYPizzaFactory.cs
│ └── ChicagoPizzaFactory.cs
├── Program.cs
├── Pizza
│ ├── Pizza.cs
│ ├── ClamPizza.cs
│ ├── CheesePizza.cs
│ └── VeggiePizza.cs
├── Properties
│ └── AssemblyInfo.cs
└── FactoryPattern.csproj
├── CompositePattern
├── App.config
├── Client.cs
├── MenuItem.cs
├── MenuComponent.cs
├── Menu.cs
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── CompositePattern.csproj
├── DecoratorPattern
├── App.config
├── CondimentDecorator.cs
├── Beverage.cs
├── Espresso.cs
├── DarkRoast.cs
├── HouseBlend.cs
├── MochaCondiment.cs
├── WhipCondiment.cs
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── DecoratorPattern.csproj
├── FacadePattern
├── App.config
├── Dvd.cs
├── Dimmer.cs
├── Program.cs
├── DvdPlayer.cs
├── HometheaterFacade.cs
├── Properties
│ └── AssemblyInfo.cs
└── FacadePattern.csproj
├── IteratorPattern
├── App.config
├── Program.cs
├── Menu.cs
├── DinnerMenuIterator.cs
├── BreakfastMenuIterator.cs
├── Client.cs
├── BreakfastMenu.cs
├── DinnerMenu.cs
├── BreakfastMenuEnum.cs
├── DinnerMenuEnum.cs
├── Properties
│ └── AssemblyInfo.cs
└── IteratorPattern.csproj
├── ObserverPattern
├── App.config
├── Weather.cs
├── Program.cs
├── Unsubscriber.cs
├── WeatherSupplier.cs
├── Properties
│ └── AssemblyInfo.cs
├── WeatherMonitor.cs
└── ObserverPattern.csproj
├── SingletonPattern
├── App.config
├── Status.cs
├── Program.cs
├── ChocolateBoiler.cs
├── Properties
│ └── AssemblyInfo.cs
└── SingletonPattern.csproj
├── TemplatePattern
├── App.config
├── Beverages
│ ├── Coffee.cs
│ ├── Tea.cs
│ └── Beverage.cs
├── Comparable
│ └── Person.cs
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── TemplatePattern.csproj
├── README.md
├── .gitattributes
├── .gitignore
└── DesignPatterns.sln
/StrategyPattern/IFlyBehaviour.cs:
--------------------------------------------------------------------------------
1 | namespace Ducks
2 | {
3 | internal interface IFlyBehaviour
4 | {
5 | void Fly();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/StrategyPattern/IQuackBehaviour.cs:
--------------------------------------------------------------------------------
1 | namespace Ducks
2 | {
3 | internal interface IQuackBehaviour
4 | {
5 | void Quack();
6 | }
7 | }
--------------------------------------------------------------------------------
/AdapterPattern/IDuck.cs:
--------------------------------------------------------------------------------
1 | namespace AdapterPattern
2 | {
3 | public interface IDuck
4 | {
5 | void Quack();
6 | void Fly();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/AdapterPattern/ITurkey.cs:
--------------------------------------------------------------------------------
1 | namespace AdapterPattern
2 | {
3 | public interface ITurkey
4 | {
5 | void Gobble();
6 | void Fly();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/CommandPattern/ICommand.cs:
--------------------------------------------------------------------------------
1 | namespace CommandPattern
2 | {
3 | internal interface ICommand
4 | {
5 | void Execute();
6 | void Undo();
7 | }
8 | }
--------------------------------------------------------------------------------
/StatePattern/Legacy/State.cs:
--------------------------------------------------------------------------------
1 | namespace StatePattern.Legacy
2 | {
3 | public enum State
4 | {
5 | Sold, HasQuarters, NoQuarters, NoGumballs
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/Intefaces/IClam.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | public interface IClam
4 | {
5 | string Name { get; }
6 | }
7 | }
--------------------------------------------------------------------------------
/CommandPattern/OnOffStruct.cs:
--------------------------------------------------------------------------------
1 | namespace CommandPattern
2 | {
3 | internal struct OnOffStruct
4 | {
5 | public ICommand On;
6 | public ICommand Off;
7 | }
8 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/Intefaces/ICheese.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | public interface ICheese
4 | {
5 | string Name { get; }
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/Intefaces/IDough.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | public interface IDough
4 | {
5 | string Name { get; }
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/Intefaces/ISauce.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | public interface ISauce
4 | {
5 | string Name { get; }
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/Intefaces/IVeggies.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | public interface IVeggies
4 | {
5 | string Name { get; }
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/Olive.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class Olive : IVeggies
4 | {
5 | public string Name => "Olives";
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/Cucumber.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class Cucumber : IVeggies
4 | {
5 | public string Name => "Cucumber";
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/DeepDish.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class DeepDish : IDough
4 | {
5 | public string Name => "Deep Dish";
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/FreshClam.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class FreshClam : IClam
4 | {
5 | public string Name => "Fresh Clam";
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/Mozarella.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class Mozarella : ICheese
4 | {
5 | public string Name => "Mozarella";
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/Parmesan.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class Parmesan : ICheese
4 | {
5 | public string Name => "Parmesan";
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/ThinCrust.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class ThinCrust : IDough
4 | {
5 | public string Name => "Thin Crust";
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/FrozenClam.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class FrozenClam : IClam
4 | {
5 | public string Name => "Frozen Clam";
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/Pepper.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class Pepper : IVeggies
4 | {
5 |
6 | public string Name => "Bell Peppers";
7 | }
8 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/PlumTomato.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class PlumTomato : ISauce
4 | {
5 | public string Name => "Plum Tomato";
6 | }
7 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/CherryTomato.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class CherryTomato : ISauce
4 | {
5 | public string Name => "Cherry Tomato";
6 | }
7 | }
--------------------------------------------------------------------------------
/CommandPattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/AdapterPattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CompositePattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/DecoratorPattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/DecoratorPattern/CondimentDecorator.cs:
--------------------------------------------------------------------------------
1 | namespace DecoratorPattern
2 | {
3 | abstract class CondimentDecorator : Beverage
4 | {
5 | public abstract override string Description { get; }
6 | }
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/FacadePattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/FactoryPattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/IteratorPattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ObserverPattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/SingletonPattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/StatePattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/StrategyPattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/TemplatePattern/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/StatePattern/IState.cs:
--------------------------------------------------------------------------------
1 | namespace StatePattern
2 | {
3 | public interface IState
4 | {
5 | void InsertQuarter();
6 | void EjectQuarter();
7 | void TurnCrank();
8 | void Dispense();
9 | }
10 | }
--------------------------------------------------------------------------------
/FacadePattern/Dvd.cs:
--------------------------------------------------------------------------------
1 | namespace FacadePattern
2 | {
3 | public class Dvd
4 | {
5 | public Dvd(string name)
6 | {
7 | Movie = name;
8 | }
9 | public string Movie { get; set; }
10 | }
11 | }
--------------------------------------------------------------------------------
/SingletonPattern/Status.cs:
--------------------------------------------------------------------------------
1 | namespace SingletonPattern
2 | {
3 | internal partial class ChocolateBoiler
4 | {
5 | private enum Status
6 | {
7 | Empty, InProgress, Boiled
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/Ingredients/Onion.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | internal class Onion : IVeggies
4 | {
5 | public Onion()
6 | {
7 | }
8 |
9 | public string Name => "Onions";
10 | }
11 | }
--------------------------------------------------------------------------------
/StrategyPattern/FlyNope.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Ducks
4 | {
5 | class FlyNope : IFlyBehaviour
6 | {
7 | public void Fly()
8 | {
9 | Console.WriteLine("I can't fly");
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/StrategyPattern/FlyWings.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Ducks
4 | {
5 | class FlyWings : IFlyBehaviour
6 | {
7 | public void Fly()
8 | {
9 | Console.WriteLine("Flap Flap");
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/StrategyPattern/QuackNope.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Ducks
4 | {
5 | internal class QuackNope : IQuackBehaviour
6 | {
7 | public void Quack()
8 | {
9 | Console.WriteLine("...");
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/StrategyPattern/QuackSqueak.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Ducks
4 | {
5 | class QuackSqueak : IQuackBehaviour
6 | {
7 | public void Quack()
8 | {
9 | Console.WriteLine("Squeeeak");
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/StrategyPattern/QuackNormal.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Ducks
4 | {
5 | class QuackNormal : IQuackBehaviour
6 | {
7 | public void Quack()
8 | {
9 | Console.WriteLine("Quack Quack");
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/DecoratorPattern/Beverage.cs:
--------------------------------------------------------------------------------
1 | namespace DecoratorPattern
2 | {
3 | abstract class Beverage
4 | {
5 | protected string _description = "No Description";
6 | public abstract string Description { get; }
7 | public abstract double Cost();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/CommandPattern/NoCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace CommandPattern
4 | {
5 | internal class NoCommand : ICommand
6 | {
7 | public void Execute()
8 | {
9 | Console.WriteLine("No Command Assigned");
10 | }
11 |
12 | public void Undo()
13 | {
14 | Execute();
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/CompositePattern/Client.cs:
--------------------------------------------------------------------------------
1 | namespace CompositePattern
2 | {
3 | public class Client
4 | {
5 | private readonly MenuComponent _menus;
6 |
7 | public Client(MenuComponent menus)
8 | {
9 | _menus = menus;
10 | }
11 |
12 | public void Print()
13 | {
14 | _menus.Print();
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/IIngredientsFactory.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace FactoryPattern
4 | {
5 | interface IIngredientsFactory
6 | {
7 | IDough CreateDough();
8 | IEnumerable CreateVeggies();
9 | ISauce CreateSauce();
10 | ICheese CreateCheese();
11 | IClam CreateClam();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/IteratorPattern/Program.cs:
--------------------------------------------------------------------------------
1 | namespace IteratorPattern
2 | {
3 | static class Program
4 | {
5 | private static void Main()
6 | {
7 | var breakfast = new BreakfastMenu();
8 | var dinner = new DinnerMenu();
9 | var waiter = new Client(breakfast,dinner);
10 | waiter.PrintMenu();
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/DecoratorPattern/Espresso.cs:
--------------------------------------------------------------------------------
1 | namespace DecoratorPattern
2 | {
3 | class Espresso : Beverage
4 | {
5 | public Espresso()
6 | {
7 | _description = "Espresso";
8 | }
9 |
10 | public override string Description => _description;
11 |
12 | public override double Cost()
13 | {
14 | return 1.99;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/DecoratorPattern/DarkRoast.cs:
--------------------------------------------------------------------------------
1 | namespace DecoratorPattern
2 | {
3 | internal class DarkRoast : Beverage
4 | {
5 | public DarkRoast()
6 | {
7 | _description = "Dark Roast";
8 | }
9 |
10 | public override string Description => _description;
11 |
12 | public override double Cost()
13 | {
14 | return 1.49;
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/DecoratorPattern/HouseBlend.cs:
--------------------------------------------------------------------------------
1 | namespace DecoratorPattern
2 | {
3 | class HouseBlend : Beverage
4 | {
5 | public HouseBlend()
6 | {
7 | _description = "House Blend";
8 | }
9 |
10 | public override string Description => _description;
11 |
12 | public override double Cost()
13 | {
14 | return 2.49;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/TemplatePattern/Beverages/Coffee.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace TemplatePattern
4 | {
5 | class Coffee : Beverage
6 | {
7 | protected override void Brew()
8 | {
9 | Console.WriteLine("Add Coffe Grounds to water and boil");
10 | }
11 |
12 | protected override void AddCondiments()
13 | {
14 | Console.WriteLine("Add Milk and Sugar");
15 | }
16 |
17 | }
18 | }
--------------------------------------------------------------------------------
/ObserverPattern/Weather.cs:
--------------------------------------------------------------------------------
1 | namespace ObserverPattern
2 | {
3 | class Weather
4 | {
5 | public double Pressure { get; }
6 |
7 | public double Humidity { get; }
8 |
9 | public double Temperature { get; }
10 |
11 | public Weather(double humd, double pres, double temp)
12 | {
13 | Temperature = temp;
14 | Pressure = pres;
15 | Humidity = humd;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/FactoryPattern/Factory Method/PizzaFactory.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | abstract class PizzaFactory
4 | {
5 | public Pizza Order(string type)
6 | {
7 | var pizza = Create(type);
8 | pizza.Prepare();
9 | pizza.Bake();
10 | pizza.Cut();
11 | pizza.Box();
12 | return pizza;
13 | }
14 |
15 | protected abstract Pizza Create(string type);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/AdapterPattern/Program.cs:
--------------------------------------------------------------------------------
1 | namespace AdapterPattern
2 | {
3 | internal static class Program
4 | {
5 | private static void Main()
6 | {
7 | var turkey = new WildTurkey();
8 | var adapter = new TurkeyAdapter(turkey);
9 |
10 | Tester(adapter);
11 | }
12 |
13 | private static void Tester(IDuck duck)
14 | {
15 | duck.Fly();
16 | duck.Quack();
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/CommandPattern/LightOnCommand.cs:
--------------------------------------------------------------------------------
1 | namespace CommandPattern
2 | {
3 | internal class LightOnCommand : ICommand
4 | {
5 | private readonly Light _light;
6 |
7 | public LightOnCommand(Light l)
8 | {
9 | _light = l;
10 | }
11 |
12 | public void Execute()
13 | {
14 | _light.On();
15 | }
16 |
17 | public void Undo()
18 | {
19 | _light.Off();
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/CommandPattern/LightOffCommand.cs:
--------------------------------------------------------------------------------
1 | namespace CommandPattern
2 | {
3 | internal class LightOffCommand : ICommand
4 | {
5 | private readonly Light _light;
6 |
7 | public LightOffCommand(Light l)
8 | {
9 | _light = l;
10 | }
11 |
12 | public void Execute()
13 | {
14 | _light.Off();
15 | }
16 |
17 | public void Undo()
18 | {
19 | _light.On();
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/FacadePattern/Dimmer.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 FacadePattern
8 | {
9 | public class Dimmer
10 | {
11 | internal void Dim(int val)
12 | {
13 | Console.WriteLine(val == 10 ? "Turning Lights On" : $"Dimming lights to {val}");
14 | }
15 |
16 | internal void Off() => Console.WriteLine("Switching off lights");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/AdapterPattern/MallardDuck.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 AdapterPattern
8 | {
9 | class MallardDuck : IDuck
10 | {
11 | public void Quack()
12 | {
13 | Console.WriteLine("Quack Quack Quack");
14 | }
15 |
16 | public void Fly()
17 | {
18 | Console.WriteLine("Flies 500 Metres");
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/AdapterPattern/WildTurkey.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 AdapterPattern
8 | {
9 | class WildTurkey : ITurkey
10 | {
11 | public void Gobble()
12 | {
13 | Console.WriteLine("Gobble Gobble Gobble");
14 | }
15 |
16 | public void Fly()
17 | {
18 | Console.WriteLine("Flies 100 Metres");
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/CommandPattern/GarageDoorOpenCommand.cs:
--------------------------------------------------------------------------------
1 | namespace CommandPattern
2 | {
3 | internal class GarageDoorOpenCommand : ICommand
4 | {
5 | private readonly Garage _garage;
6 |
7 | public GarageDoorOpenCommand(Garage g)
8 | {
9 | _garage = g;
10 | }
11 |
12 | public void Execute()
13 | {
14 | _garage.Open();
15 | }
16 |
17 | public void Undo()
18 | {
19 | _garage.Close();
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/CommandPattern/GarageDoorCloseCommand.cs:
--------------------------------------------------------------------------------
1 | namespace CommandPattern
2 | {
3 | internal class GarageDoorCloseCommand : ICommand
4 | {
5 | private readonly Garage _garage;
6 |
7 | public GarageDoorCloseCommand(Garage g)
8 | {
9 | _garage = g;
10 | }
11 |
12 | public void Execute()
13 | {
14 | _garage.Close();
15 | }
16 |
17 | public void Undo()
18 | {
19 | _garage.Open();
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/CommandPattern/Light.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace CommandPattern
4 | {
5 | public class Light
6 | {
7 | private readonly string _name;
8 |
9 | public Light(string name)
10 | {
11 | _name = name;
12 | }
13 |
14 | internal void On()
15 | {
16 | Console.WriteLine($"{_name} Light On");
17 | }
18 |
19 | internal void Off()
20 | {
21 | Console.WriteLine($"{_name} Light Off");
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/FactoryPattern/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace FactoryPattern
4 | {
5 | static class Program
6 | {
7 | static void Main()
8 | {
9 | Console.WriteLine("Yankees fan orders:");
10 | var yankees = new NyPizzaFactory();
11 | yankees.Order("Cheese");
12 | Console.WriteLine();
13 | Console.WriteLine("Cubs fan orders:");
14 | var cubs = new ChicagoPizzaFactory();
15 | cubs.Order("Clam");
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/CommandPattern/Garage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace CommandPattern
4 | {
5 | internal class Garage
6 | {
7 | private readonly string _name;
8 |
9 | public Garage(string name)
10 | {
11 | _name = name;
12 | }
13 |
14 | internal void Open()
15 | {
16 | Console.WriteLine($"{_name} Garage Opened");
17 | }
18 |
19 | internal void Close()
20 | {
21 | Console.WriteLine($"{_name} Garage Closed");
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/IteratorPattern/Menu.cs:
--------------------------------------------------------------------------------
1 | namespace IteratorPattern
2 | {
3 | public class Menu
4 | {
5 | public string Name { get; }
6 | public string Description { get; }
7 | public bool Vegetarian { get; }
8 | public double Price { get; }
9 |
10 | public Menu(string name, string description, double price, bool vegetarian)
11 | {
12 | Name = name;
13 | Description = description;
14 | Price = price;
15 | Vegetarian = vegetarian;
16 | }
17 |
18 | }
19 | }
--------------------------------------------------------------------------------
/SingletonPattern/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SingletonPattern
4 | {
5 | static class Program
6 | {
7 | static void Main()
8 | {
9 | try
10 | {
11 | var chocoEggs = ChocolateBoiler.GetInstance();
12 | chocoEggs.Fill();
13 | chocoEggs.Boil();
14 | chocoEggs.Drain();
15 | }
16 | catch (Exception)
17 | {
18 | Console.Write("Oops");
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/CommandPattern/MacroCommand.cs:
--------------------------------------------------------------------------------
1 | namespace CommandPattern
2 | {
3 | internal class MacroCommand : ICommand
4 | {
5 | private readonly ICommand[] _commands;
6 |
7 | public MacroCommand(ICommand[] commands)
8 | {
9 | _commands = commands;
10 | }
11 |
12 | public void Execute()
13 | {
14 | foreach (var item in _commands)
15 | item.Execute();
16 | }
17 |
18 | public void Undo()
19 | {
20 | foreach (var item in _commands)
21 | item.Undo();
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/ObserverPattern/Program.cs:
--------------------------------------------------------------------------------
1 | namespace ObserverPattern
2 | {
3 | static class Program
4 | {
5 | static void Main()
6 | {
7 | var provider = new WeatherSupplier();
8 | var observer1 = new WeatherMonitor("TP");
9 | var observer2 = new WeatherMonitor("H");
10 | provider.WeatherConditions(32.0, 0.05, 1.5);
11 | observer1.Subscribe(provider);
12 | provider.WeatherConditions(33.5, 0.04, 1.7);
13 | observer2.Subscribe(provider);
14 | provider.WeatherConditions(37.5, 0.07, 1.2);
15 |
16 |
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/IteratorPattern/DinnerMenuIterator.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 |
4 | namespace IteratorPattern
5 | {
6 | class DinnerMenuIterator : IEnumerable
7 | {
8 | private int _count = 0;
9 | private Menu[] _items;
10 |
11 | public DinnerMenuIterator(Menu[] items)
12 | {
13 | _items = items;
14 | }
15 |
16 | IEnumerator IEnumerable.GetEnumerator()
17 | {
18 | return GetEnumerator();
19 | }
20 |
21 | public IEnumerator GetEnumerator()
22 | {
23 | return new DinnerMenuEnum(_items);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/IteratorPattern/BreakfastMenuIterator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | namespace IteratorPattern
6 | {
7 | class BreakfastMenuIterator : IEnumerable
8 | {
9 | private int _count = 0;
10 | private ArrayList _items;
11 |
12 | public BreakfastMenuIterator(ArrayList items)
13 | {
14 | _items = items;
15 | }
16 |
17 | IEnumerator IEnumerable.GetEnumerator()
18 | {
19 | return GetEnumerator();
20 | }
21 |
22 | public IEnumerator GetEnumerator()
23 | {
24 | return new BreakfastMenuEnum(_items);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/AdapterPattern/TurkeyAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace AdapterPattern
6 | {
7 | public class TurkeyAdapter : IDuck
8 | {
9 | private readonly ITurkey _turkey;
10 |
11 | public TurkeyAdapter(ITurkey turkey)
12 | {
13 | _turkey = turkey;
14 | }
15 | public void Quack()
16 | {
17 | _turkey.Gobble();
18 | }
19 |
20 | public void Fly()
21 | {
22 | for (var i = 0; i < 5; i++)
23 | {
24 | _turkey.Fly();
25 | Console.WriteLine("Resting..");
26 | }
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/FactoryPattern/Pizza/Pizza.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace FactoryPattern
4 | {
5 | abstract class Pizza
6 | {
7 | public string Color;
8 |
9 | internal abstract void Prepare();
10 | internal void Bake()
11 | {
12 | Console.WriteLine("Baking at 135 degree Celsius for 20 minutes");
13 | }
14 | internal void Cut()
15 | {
16 | Console.WriteLine("Cutting into diagonal pieces");
17 | }
18 | internal void Box()
19 | {
20 | Console.WriteLine("Putting pizza in " + Color + " coloured box");
21 | }
22 |
23 | public string Name { protected get; set; }
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/TemplatePattern/Beverages/Tea.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace TemplatePattern
4 | {
5 | class Tea : Beverage
6 | {
7 | protected override void Brew()
8 | {
9 | Console.WriteLine("Adding tea leaves to water and boil");
10 | }
11 |
12 | protected override void AddCondiments()
13 | {
14 | Console.WriteLine("Adding Lemon and Sugar");
15 | Sugar();
16 | }
17 |
18 | private new void Sugar()
19 | {
20 | Console.WriteLine($"adding {_sugar} spoons of sugar");
21 | }
22 |
23 | public new int AddSugar
24 | {
25 | set { _sugar = value; }
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/ObserverPattern/Unsubscriber.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace ObserverPattern
5 | {
6 | internal class Unsubscriber : IDisposable
7 | {
8 | private readonly List> _observers;
9 | private readonly IObserver _observer;
10 |
11 | internal Unsubscriber(List> observers, IObserver observer)
12 | {
13 | _observers = observers;
14 | _observer = observer;
15 | }
16 |
17 | public void Dispose()
18 | {
19 | if (_observers.Contains(_observer))
20 | _observers.Remove(_observer);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/FacadePattern/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace FacadePattern
4 | {
5 | internal static class Program
6 | {
7 | private static void Main()
8 | {
9 | var dimmer = new Dimmer();
10 | var dvdPlayer = new DvdPlayer();
11 | var dvd = new Dvd("Gone with the Wind 2 : Electric Bugaloo");
12 | var homeTheater = new HomeTheatreFacade(dimmer,dvd,dvdPlayer);
13 |
14 | homeTheater.WatchMovie();
15 | Console.WriteLine();
16 | homeTheater.Pause();
17 | Console.WriteLine();
18 | homeTheater.Resume();
19 | Console.WriteLine();
20 | homeTheater.Pause();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/FactoryPattern/Pizza/ClamPizza.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace FactoryPattern
4 | {
5 | class ClamPizza : Pizza
6 | {
7 | readonly IIngredientsFactory _ingredients;
8 |
9 | public ClamPizza(IIngredientsFactory ing)
10 | {
11 | _ingredients = ing;
12 | }
13 |
14 | internal override void Prepare()
15 | {
16 | Console.WriteLine("Preparing " + Name + " Using");
17 | Console.Write("Dough: " + _ingredients.CreateDough().Name + ", Clam: " + _ingredients.CreateClam().Name + ", Sauce: " + _ingredients.CreateSauce().Name + ", Cheese: " + _ingredients.CreateCheese().Name);
18 | Console.WriteLine();
19 |
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/DecoratorPattern/MochaCondiment.cs:
--------------------------------------------------------------------------------
1 | namespace DecoratorPattern
2 | {
3 | class MochaCondiment : CondimentDecorator
4 | {
5 | Beverage _beverage;
6 |
7 | public MochaCondiment(Beverage beverage)
8 | {
9 | this._beverage = beverage;
10 | }
11 |
12 | public override string Description {
13 | get
14 | {
15 | if (_beverage.Description.StartsWith("Mocha")){
16 | return "Double " + _beverage.Description;
17 | }
18 | else
19 | return "Mocha " + _beverage.Description;
20 | }
21 | }
22 |
23 | public override double Cost()
24 | {
25 | return 0.2 + _beverage.Cost();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/CompositePattern/MenuItem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace CompositePattern
4 | {
5 | public class MenuItem : MenuComponent
6 | {
7 | public MenuItem(string name, string description, double price, bool isveg)
8 | {
9 | Name = name;
10 | Description = description;
11 | Price = price;
12 | Vegetarian = isveg;
13 | }
14 |
15 | public override string Name { get; }
16 |
17 | public override string Description { get; }
18 |
19 | public override double Price { get; }
20 |
21 | public override bool Vegetarian { get; }
22 |
23 | public override void Print()
24 | {
25 | Console.WriteLine($"{Name} : {Price} {(Vegetarian ? '+' : '*')} \n {Description}");
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/DecoratorPattern/WhipCondiment.cs:
--------------------------------------------------------------------------------
1 | namespace DecoratorPattern
2 | {
3 | class WhipCondiment : CondimentDecorator
4 | {
5 | Beverage _beverage;
6 |
7 | public WhipCondiment(Beverage beverage)
8 | {
9 | this._beverage = beverage;
10 | }
11 |
12 | public override string Description
13 | {
14 | get
15 | {
16 | if (_beverage.Description.StartsWith("Whip"))
17 | {
18 | return "Double " + _beverage.Description;
19 | }
20 | else
21 | return "Whip " + _beverage.Description;
22 | }
23 | }
24 |
25 | public override double Cost()
26 | {
27 | return 0.15 + _beverage.Cost();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/FacadePattern/DvdPlayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace FacadePattern
4 | {
5 | public class DvdPlayer
6 | {
7 | private Dvd _dvd;
8 | private int _time = 0;
9 | public void On() => Console.WriteLine("DVD Player powered on");
10 |
11 | public void Insert(Dvd dvd)
12 | {
13 | _dvd = dvd;
14 | Console.WriteLine($"Inserting {dvd.Movie}");
15 |
16 | }
17 |
18 | public void Play() => Console.WriteLine($"Playing {_dvd.Movie}");
19 |
20 | public void Pause()
21 | {
22 | Console.WriteLine($"Pausing at {_time = (new Random()).Next(_time,_time + 120)}");
23 | }
24 |
25 | public void Resume()
26 | {
27 | Console.WriteLine($"Resuming from {_time}");
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/StatePattern/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace StatePattern
4 | {
5 | static class Program
6 | {
7 | public static void Main()
8 | {
9 | LegacyTest();
10 | Console.WriteLine();
11 | var gumballmachine = new GumballMachine(5);
12 | gumballmachine.InsertQuarter();
13 | gumballmachine.TurnCrank();
14 | gumballmachine.InsertQuarter();
15 | gumballmachine.TurnCrank();
16 | }
17 |
18 | private static void LegacyTest()
19 | {
20 | var machine = new Legacy.GumballMachine(2);
21 | machine.InsertQuarter();
22 | machine.TurnCrank();
23 | machine.InsertQuarter();
24 | machine.EjectQuarter();
25 | machine.InsertQuarter();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/FactoryPattern/Factory Method/NYPizzaFactory.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | class NyPizzaFactory : PizzaFactory
4 | {
5 | protected override Pizza Create(string type)
6 | {
7 | Pizza pizza;
8 | IIngredientsFactory ingredients = new NyIngredientsFactory();
9 |
10 | if (type.Equals("Cheese"))
11 | {
12 | pizza = new CheesePizza(ingredients) {Name = "NY Style Cheese"};
13 | }
14 | else if (type.Equals("Clam"))
15 | {
16 | pizza = new ClamPizza(ingredients) {Name = "NY Style Clam"};
17 | }
18 | else
19 | {
20 | pizza = new VeggiePizza(ingredients) {Name = "NY Style Veggie"};
21 | }
22 | pizza.Color = "blue";
23 | return pizza;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/StatePattern/SoldOutState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace StatePattern
4 | {
5 | public class SoldOutState : IState
6 | {
7 | public GumballMachine Machine { get; }
8 |
9 | public SoldOutState(GumballMachine gumballMachine)
10 | {
11 | Machine = gumballMachine;
12 | }
13 |
14 | public void InsertQuarter()
15 | {
16 | Console.WriteLine("Sorry! Sold Out");
17 | }
18 |
19 | public void EjectQuarter()
20 | {
21 | Console.WriteLine("Can't eject when sold out");
22 | }
23 |
24 | public void TurnCrank()
25 | {
26 | Console.WriteLine("turning crank achieves nothing");
27 | }
28 |
29 | public void Dispense()
30 | {
31 | Console.WriteLine("Can't dispense when out of stock");
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/TemplatePattern/Comparable/Person.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace TemplatePattern.Comparable
4 | {
5 | class Person : IComparable
6 | {
7 | public string Name { get; }
8 | public int Age { get; }
9 |
10 | public Person(string name, int age)
11 | {
12 | Name = name;
13 | Age = age;
14 | }
15 |
16 | public int CompareTo(object obj)
17 | {
18 | var other = (Person)obj;
19 | if (String.Compare(Name, other.Name, StringComparison.Ordinal) == 0)
20 | {
21 | return Age.CompareTo(other.Age);
22 | }
23 | return String.Compare(Name, other.Name, StringComparison.Ordinal);
24 | }
25 |
26 | public override string ToString()
27 | {
28 | return $"{Name} : {Age} < ";
29 | }
30 |
31 | }
32 | }
--------------------------------------------------------------------------------
/FactoryPattern/Pizza/CheesePizza.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace FactoryPattern
4 | {
5 | class CheesePizza : Pizza
6 | {
7 | readonly IIngredientsFactory _ingredients;
8 |
9 | public CheesePizza(IIngredientsFactory ing)
10 | {
11 | _ingredients = ing;
12 | }
13 | internal override void Prepare()
14 | {
15 | Console.WriteLine("Preparing " + Name + " Using");
16 | Console.Write("Dough: " + _ingredients.CreateDough().Name + ", Cheese: " + _ingredients.CreateCheese().Name + ", Sauce: " + _ingredients.CreateSauce().Name + ", Veggies: ");
17 | Console.WriteLine();
18 | foreach (var val in _ingredients.CreateVeggies())
19 | {
20 | Console.Write(val.Name + " ");
21 | }
22 | Console.WriteLine();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/FactoryPattern/Pizza/VeggiePizza.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace FactoryPattern
4 | {
5 | class VeggiePizza : Pizza
6 | {
7 | readonly IIngredientsFactory _ingredients;
8 |
9 | public VeggiePizza(IIngredientsFactory ing)
10 | {
11 | _ingredients = ing;
12 | }
13 | internal override void Prepare()
14 | {
15 | Console.WriteLine("Preparing " + Name + " Using");
16 | Console.Write("Dough: " + _ingredients.CreateDough().Name + ", Cheese: " + _ingredients.CreateCheese().Name + ", Sauce: " + _ingredients.CreateSauce().Name + ", Veggies: ");
17 | Console.WriteLine();
18 | foreach (var val in _ingredients.CreateVeggies())
19 | {
20 | Console.Write(val.Name + " ");
21 | }
22 | Console.WriteLine();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/StatePattern/NoQuarterState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace StatePattern
4 | {
5 | public class NoQuarterState : IState
6 | {
7 | public GumballMachine Machine { get; }
8 |
9 | public NoQuarterState(GumballMachine machine)
10 | {
11 | Machine = machine;
12 | }
13 | public void InsertQuarter()
14 | {
15 | Console.WriteLine("Inserted a quarter");
16 | Machine.State = Machine.HasQuarterState;
17 | }
18 |
19 | public void EjectQuarter()
20 | {
21 | Console.Write("Can't eject anything");
22 | }
23 |
24 | public void TurnCrank()
25 | {
26 | Console.WriteLine("Can't turn crank without a quarter");
27 | }
28 |
29 | public void Dispense()
30 | {
31 | Console.WriteLine("Can't dispense");
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/DecoratorPattern/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DecoratorPattern
4 | {
5 | static class Program
6 | {
7 | static void Main()
8 | {
9 | Beverage beverage = new Espresso();
10 | Console.WriteLine(beverage.Description + " $" + beverage.Cost());
11 |
12 | Beverage beverage2 = new DarkRoast();
13 | beverage2 = new MochaCondiment(beverage2);
14 | beverage2 = new MochaCondiment(beverage2);
15 | beverage2 = new WhipCondiment(beverage2);
16 | Console.WriteLine(beverage2.Description + " $" + beverage2.Cost());
17 |
18 | Beverage beverage3 = new HouseBlend();
19 | beverage3 = new MochaCondiment(beverage3);
20 | beverage3 = new WhipCondiment(beverage3);
21 | Console.WriteLine(beverage3.Description + " $" + beverage3.Cost());
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/CompositePattern/MenuComponent.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace CompositePattern
4 | {
5 | public class MenuComponent
6 | {
7 | public virtual void Add(MenuComponent component)
8 | {
9 | throw new NotImplementedException();
10 | }
11 |
12 | public virtual void Remove(MenuComponent component)
13 | {
14 | throw new NotImplementedException();
15 | }
16 |
17 | public virtual MenuComponent GetChild(int i)
18 | {
19 | throw new NotImplementedException();
20 | }
21 |
22 | public virtual string Name { get; }
23 | public virtual string Description { get; }
24 | public virtual bool Vegetarian { get; }
25 | public virtual double Price { get; }
26 |
27 | public virtual void Print()
28 | {
29 | throw new NotImplementedException();
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/NYIngredientsFactory.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace FactoryPattern
4 | {
5 | internal class NyIngredientsFactory : IIngredientsFactory
6 | {
7 | ICheese IIngredientsFactory.CreateCheese()
8 | {
9 | return new Mozarella();
10 | }
11 |
12 | IClam IIngredientsFactory.CreateClam()
13 | {
14 | return new FrozenClam();
15 | }
16 |
17 | IDough IIngredientsFactory.CreateDough()
18 | {
19 | return new ThinCrust();
20 | }
21 |
22 | ISauce IIngredientsFactory.CreateSauce()
23 | {
24 | return new CherryTomato();
25 | }
26 |
27 | IEnumerable IIngredientsFactory.CreateVeggies()
28 | {
29 | IVeggies[] arr = { new Onion(), new Pepper(), new Olive() };
30 | return arr;
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/FacadePattern/HometheaterFacade.cs:
--------------------------------------------------------------------------------
1 | namespace FacadePattern
2 | {
3 | public class HomeTheatreFacade
4 | {
5 | private Dimmer _dimmer;
6 | private Dvd _dvd;
7 | private DvdPlayer _dvdPlayer;
8 |
9 | public HomeTheatreFacade(Dimmer dimmer,Dvd dvd, DvdPlayer dvdPlayer)
10 | {
11 | _dvd = dvd;
12 | _dimmer = dimmer;
13 | _dvdPlayer = dvdPlayer;
14 | }
15 |
16 | public void WatchMovie()
17 | {
18 | _dimmer.Dim(5);
19 | _dvdPlayer.On();
20 | _dvdPlayer.Insert(_dvd);
21 | _dvdPlayer.Play();
22 | }
23 |
24 | public void Pause()
25 | {
26 | _dimmer.Dim(10);
27 | _dvdPlayer.Pause();
28 | }
29 |
30 | public void Resume()
31 | {
32 | _dimmer.Dim(5);
33 | _dvdPlayer.Resume();
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/TemplatePattern/Beverages/Beverage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace TemplatePattern
4 | {
5 | public abstract class Beverage
6 | {
7 | // ReSharper disable once InconsistentNaming
8 | protected int _sugar;
9 | public void Prepare()
10 | {
11 | Boil();
12 | Brew();
13 | Pour();
14 | if (WantsCondiments)
15 | AddCondiments();
16 |
17 | }
18 |
19 | public bool WantsCondiments { private get; set; }
20 |
21 |
22 | protected abstract void Brew();
23 |
24 | private void Boil()
25 | {
26 | Console.WriteLine("Boling Water");
27 | }
28 |
29 | private void Pour()
30 | {
31 | Console.WriteLine("Pouring in Cup");
32 | }
33 |
34 | protected abstract void AddCondiments();
35 |
36 | public int AddSugar { get; set; }
37 |
38 | protected void Sugar() { }
39 | }
40 | }
--------------------------------------------------------------------------------
/FactoryPattern/Factory Method/ChicagoPizzaFactory.cs:
--------------------------------------------------------------------------------
1 | namespace FactoryPattern
2 | {
3 | class ChicagoPizzaFactory : PizzaFactory
4 | {
5 | protected override Pizza Create(string type)
6 | {
7 | Pizza pizza;
8 | IIngredientsFactory ingredients = new ChicagoIngredientsFactory();
9 |
10 | if (type.Equals("Cheese"))
11 | {
12 | pizza = new CheesePizza(ingredients);
13 | pizza.Name = "Chicago Cheese";
14 | }
15 | else if (type.Equals("Clam"))
16 | {
17 | pizza = new ClamPizza(ingredients);
18 | pizza.Name = "Chicago Clam";
19 | }
20 | else
21 | {
22 | pizza = new VeggiePizza(ingredients);
23 | pizza.Name = "Chicago Veggie";
24 | }
25 | pizza.Color = "red";
26 | return pizza;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/IteratorPattern/Client.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 |
4 | namespace IteratorPattern
5 | {
6 | public class Client
7 | {
8 | private IEnumerable _breakfast;
9 | private IEnumerable _dinner;
10 |
11 | public Client(BreakfastMenu breakfast, DinnerMenu dinner)
12 | {
13 | this._breakfast = breakfast.Items;
14 | this._dinner = dinner.Items;
15 | }
16 |
17 | public void PrintMenu()
18 | {
19 | var breakfast = _breakfast;
20 | PrintMenu(breakfast);
21 | var dinner = _dinner;
22 | PrintMenu(dinner);
23 | }
24 |
25 | private void PrintMenu(IEnumerable iter)
26 | {
27 | foreach (var item in iter)
28 | {
29 | var i = (Menu) item;
30 | Console.WriteLine($"{i.Name} Rs. {i.Price} { (i.Vegetarian ? "*" : "x") } \n {i.Description} ");
31 |
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/FactoryPattern/Abstract Factory/ChicagoIngredientsFactory.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace FactoryPattern
4 | {
5 | internal class ChicagoIngredientsFactory : IIngredientsFactory
6 | {
7 | ICheese IIngredientsFactory.CreateCheese()
8 | {
9 | return new Parmesan();
10 | }
11 |
12 | IClam IIngredientsFactory.CreateClam()
13 | {
14 | return new FreshClam();
15 | }
16 |
17 | IDough IIngredientsFactory.CreateDough()
18 | {
19 | return new DeepDish();
20 | }
21 |
22 | ISauce IIngredientsFactory.CreateSauce()
23 | {
24 | return new PlumTomato();
25 | }
26 |
27 | IEnumerable IIngredientsFactory.CreateVeggies()
28 | {
29 | var oni = new Onion();
30 | var ccm = new Cucumber();
31 | var ppr = new Pepper();
32 | IVeggies[] arr = { oni, ccm, ppr };
33 | return arr;
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/IteratorPattern/BreakfastMenu.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 |
3 | namespace IteratorPattern
4 | {
5 | public class BreakfastMenu
6 | {
7 | private ArrayList _items;
8 |
9 | public IEnumerable Items
10 | {
11 | get
12 | {
13 | return new BreakfastMenuIterator(_items);
14 | }
15 | }
16 |
17 | public BreakfastMenu()
18 | {
19 | _items = new ArrayList();
20 |
21 | AddItem("Waffle", "Blueberry Sauce topped breakfast Waffles", 125, false);
22 | AddItem("Sandwich", "Veggie Sandwich with tomato and cucumber", 75, true);
23 | AddItem("Pankcakes", "Maple syrup Pancakes",110,false);
24 | AddItem("Corn Flakes", "Cornflakes with fruits and nuts",60,true);
25 | }
26 |
27 | private void AddItem(string name, string description, int price, bool veg)
28 | {
29 | var item = new Menu(name,description,price,veg);
30 | _items.Add(item);
31 | }
32 |
33 |
34 | }
35 | }
--------------------------------------------------------------------------------
/TemplatePattern/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using TemplatePattern.Comparable;
4 |
5 | namespace TemplatePattern
6 | {
7 | internal static class Program
8 | {
9 | static void Main()
10 | {
11 | var tea = new Tea();
12 | var coffee = new Coffee();
13 | tea.WantsCondiments = true;
14 | tea.AddSugar = 5;
15 | tea.Prepare();
16 |
17 | Console.WriteLine();
18 | coffee.WantsCondiments = true;
19 | coffee.Prepare();
20 |
21 | var people = new List { new Person("Ram", 25), new Person("Abishek", 12), new Person("Ram", 18), new Person("Abishek", 18) };
22 | foreach (var person in people)
23 | {
24 | Console.Write(person);
25 | }
26 | people.Sort();
27 | Console.WriteLine();
28 | foreach (var person in people)
29 | {
30 | Console.Write(person);
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/IteratorPattern/DinnerMenu.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 |
4 | namespace IteratorPattern
5 | {
6 | public class DinnerMenu
7 | {
8 | private const int Max = 1;
9 |
10 | private int _count;
11 | private Menu[] _items;
12 |
13 | public IEnumerable Items
14 | {
15 | get
16 | {
17 | return new DinnerMenuIterator(_items);
18 | }
19 | }
20 |
21 | public DinnerMenu()
22 | {
23 | _items = new Menu[Max];
24 |
25 | AddItems("Hamburger", "Hamburger with cheese and onions", 160, false);
26 |
27 | }
28 |
29 | private void AddItems(string name, string description, int price, bool veg)
30 | {
31 | var item = new Menu(name,description,price,veg);
32 |
33 | if (_count <= Max)
34 | {
35 | _items[_count] = item;
36 | _count++;
37 | }
38 | else
39 | {
40 | throw new IndexOutOfRangeException();
41 | }
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/StatePattern/SoldState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace StatePattern
4 | {
5 | public class SoldState : IState
6 | {
7 | private GumballMachine Machine { get; }
8 |
9 | public SoldState(GumballMachine gumballMachine)
10 | {
11 | Machine = gumballMachine;
12 | }
13 |
14 | public void InsertQuarter()
15 | {
16 | Console.WriteLine("Please wait, already in progress");
17 | }
18 |
19 | public void EjectQuarter()
20 | {
21 | Console.WriteLine("Can't eject, already turned the crank");
22 | }
23 |
24 | public void TurnCrank()
25 | {
26 | Console.WriteLine("Turning twice achieves nothing");
27 | }
28 |
29 | public void Dispense()
30 | {
31 | Machine.ReleaseBall();
32 | if (Machine.Count > 0)
33 | {
34 | Machine.State = Machine.NoQuarterState;
35 | }
36 | else
37 | {
38 | Console.WriteLine("Oops! No more gumballs");
39 | Machine.State = Machine.SoldOutState;
40 | }
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/IteratorPattern/BreakfastMenuEnum.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 |
4 | namespace IteratorPattern
5 | {
6 | public class BreakfastMenuEnum : IEnumerator
7 | {
8 | private readonly ArrayList _items;
9 | private int _position = -1;
10 |
11 | public BreakfastMenuEnum(ArrayList items)
12 | {
13 | _items = items;
14 | }
15 |
16 | public void Dispose()
17 | {
18 | throw new System.NotImplementedException();
19 | }
20 |
21 | public bool MoveNext()
22 | {
23 | _position++;
24 | return (_position < _items.Count);
25 | }
26 |
27 | public void Reset()
28 | {
29 | _position = -1;
30 | }
31 |
32 | object IEnumerator.Current => Current;
33 |
34 | public Menu Current
35 | {
36 | get
37 | {
38 | try
39 | {
40 | return (Menu) _items[_position];
41 | }
42 | catch (IndexOutOfRangeException)
43 | {
44 | throw new InvalidOperationException();
45 | }
46 | }
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/IteratorPattern/DinnerMenuEnum.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | namespace IteratorPattern
6 | {
7 | public class DinnerMenuEnum : IEnumerator
8 | {
9 | private readonly Menu[] _items;
10 | private int _position = -1;
11 | public DinnerMenuEnum(Menu[] items)
12 | {
13 | _items = items;
14 | }
15 |
16 | public void Dispose()
17 | {
18 | throw new System.NotImplementedException();
19 | }
20 |
21 | public bool MoveNext()
22 | {
23 | _position++;
24 | return (_position < _items.Length);
25 | }
26 |
27 | public void Reset()
28 | {
29 | _position = -1;
30 | }
31 |
32 | object IEnumerator.Current => Current;
33 |
34 | public Menu Current
35 | {
36 | get
37 | {
38 | try
39 | {
40 | return _items[_position];
41 | }
42 | catch (IndexOutOfRangeException)
43 | {
44 | throw new InvalidOperationException();
45 | }
46 | }
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DesignPatterns
2 | Design patterns are solutions to recurring problems; guidelines on how to tackle certain problems
3 | I have included implementations of some design patterns in C# to help beginners like me get their feet wet.
4 | There are better alternatives available for some of them in the .NET Framework, so this is by no means a comprehensive tutorial
5 |
6 | Any comments and suggestions are welcome. If you want to add a new design pattern implementation, just follow the naming conversation, fork my repo and submit a pull request. Same goes for any improvements and modifications.
7 |
8 | ## Types of Design Patterns
9 | ---------------------------
10 | There are three kinds of Design Patterns
11 |
12 | * Creational
13 | * Structural
14 | * Behavioral
15 |
16 | ## List of Design Pattern Implementations
17 | -----------------------------------------
18 |
19 | * [Adapter](/AdapterPattern)
20 | * [Command](/CommandPattern)
21 | * [Composite](/CompositePattern)
22 | * [Decorator](/DecoratorPattern)
23 | * [Facade](/FacadePattern)
24 | * [Factory](/FactoryPattern)
25 | * [Iterator](/IteratorPattern)
26 | * [Observer](/ObserverPattern)
27 | * [Singleton](/SingletonPattern)
28 | * [State](/StatePattern)
29 | * [Strategy](/StrategyPattern)
30 | * [Template](/TemplatePattern)
31 |
--------------------------------------------------------------------------------
/StatePattern/HasQuarterState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace StatePattern
4 | {
5 | public class HasQuarterState : IState
6 | {
7 | private GumballMachine Machine { get; }
8 | readonly Random _random = new Random(DateTime.Now.Millisecond);
9 |
10 | public HasQuarterState(GumballMachine gumballMachine)
11 | {
12 | Machine = gumballMachine;
13 | }
14 |
15 | public void InsertQuarter()
16 | {
17 | Console.WriteLine("Can't insert more than one");
18 | }
19 |
20 | public void EjectQuarter()
21 | {
22 | Console.WriteLine("Quarter returned");
23 | Machine.State = Machine.NoQuarterState;
24 | }
25 |
26 | public void TurnCrank()
27 | {
28 | Console.WriteLine("You turned the crank");
29 | var winner = _random.Next(10);
30 | if ((winner == 5) && (Machine.Count > 1))
31 | Machine.State = Machine.WinnerState;
32 | else
33 | {
34 | Machine.State = Machine.SoldState;
35 | }
36 | }
37 |
38 | public void Dispense()
39 | {
40 | Console.WriteLine("Can't do that");
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/CompositePattern/Menu.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace CompositePattern
5 | {
6 | public class Menu : MenuComponent
7 | {
8 | List _components = new List();
9 |
10 | public Menu(string name, string description)
11 | {
12 | Name = name;
13 | Description = description;
14 |
15 | }
16 |
17 | public override void Add(MenuComponent component)
18 | {
19 | _components.Add(component);
20 | }
21 |
22 | public override void Remove(MenuComponent component)
23 | {
24 | _components.Remove(component);
25 | }
26 |
27 | public override MenuComponent GetChild(int i)
28 | {
29 | return _components[i];
30 | }
31 |
32 | public override string Name { get; }
33 |
34 | public override string Description { get; }
35 |
36 | public override void Print()
37 | {
38 | Console.WriteLine(Name);
39 | Console.WriteLine("___________");
40 | foreach (var menuComponent in _components)
41 | {
42 | menuComponent.Print();
43 | }
44 | Console.WriteLine();
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/StatePattern/WinnerState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace StatePattern
4 | {
5 | public class WinnerState : IState
6 | {
7 | private GumballMachine Machine { get; }
8 |
9 | public WinnerState(GumballMachine gumballMachine)
10 | {
11 | Machine = gumballMachine;
12 | }
13 |
14 | public void InsertQuarter()
15 | {
16 | Console.WriteLine("Please wait, already in progress");
17 | }
18 |
19 | public void EjectQuarter()
20 | {
21 | Console.WriteLine("Can't eject, already turned the crank");
22 | }
23 |
24 | public void TurnCrank()
25 | {
26 | Console.WriteLine("Turning twice achieves nothing");
27 | }
28 |
29 |
30 | public void Dispense()
31 | {
32 | Console.WriteLine("You Won!! 2 gumballs for the price of one");
33 | Machine.ReleaseBall();
34 | if (Machine.Count == 0)
35 | {
36 | Machine.State = Machine.SoldOutState;
37 | Console.WriteLine("Oops! No more gumballs");
38 | }
39 | else
40 | {
41 | Machine.ReleaseBall();
42 | Machine.State = Machine.NoQuarterState;
43 | }
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/SingletonPattern/ChocolateBoiler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SingletonPattern
4 | {
5 | internal partial class ChocolateBoiler
6 | {
7 | private static readonly Lazy _singleton = new Lazy(() => new ChocolateBoiler());
8 |
9 | public static ChocolateBoiler GetInstance() => _singleton.Value;
10 |
11 | private Status _boiler;
12 |
13 | private ChocolateBoiler()
14 | {
15 | Console.WriteLine("Starting");
16 | _boiler = Status.Empty;
17 | }
18 |
19 | public void Fill()
20 | {
21 | if (!IsEmpty) return;
22 | Console.WriteLine("Filling...");
23 | _boiler = Status.InProgress;
24 | }
25 |
26 | public void Drain()
27 | {
28 | if (!IsBoiled) return;
29 | Console.WriteLine("Draining...");
30 | _boiler = Status.Empty;
31 | }
32 |
33 | public void Boil()
34 | {
35 | if (IsBoiled || IsEmpty) return;
36 | Console.WriteLine("Boiling...");
37 | _boiler = Status.Boiled;
38 | }
39 |
40 | private bool IsEmpty => (_boiler == Status.Empty);
41 |
42 | private bool IsBoiled => (_boiler == Status.Boiled);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ObserverPattern/WeatherSupplier.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace ObserverPattern
5 | {
6 | class WeatherSupplier : IObservable
7 | {
8 | private readonly List> _observers;
9 | private List Screens { get; }
10 |
11 | private List GetScreens()
12 | {
13 | return Screens;
14 | }
15 |
16 | public WeatherSupplier()
17 | {
18 | _observers = new List>();
19 | Screens = new List();
20 | }
21 |
22 | public IDisposable Subscribe(IObserver observer)
23 | {
24 | if (!_observers.Contains(observer))
25 | {
26 | _observers.Add(observer);
27 | foreach (var item in GetScreens())
28 | {
29 | observer.OnNext(item);
30 | }
31 | }
32 | return new Unsubscriber(_observers, observer);
33 | }
34 |
35 | public void WeatherConditions(double temp = 0, double humd = 0, double pres = 0)
36 | {
37 | var conditions = new Weather(humd, pres, temp);
38 | foreach (var item in _observers)
39 | item.OnNext(conditions);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/CommandPattern/RemoteControl.cs:
--------------------------------------------------------------------------------
1 | namespace CommandPattern
2 | {
3 | internal class RemoteControl
4 | {
5 | private readonly ICommand[] _offCommand;
6 | private readonly ICommand[] _onCommand;
7 | private ICommand _undoCommand;
8 |
9 | public RemoteControl(int slots)
10 | {
11 | _onCommand = new ICommand[slots];
12 | _offCommand = new ICommand[slots];
13 |
14 | var none = new NoCommand();
15 | _undoCommand = none;
16 | for (var i = 0; i < slots; i++)
17 | {
18 | _onCommand[i] = none;
19 | _offCommand[i] = none;
20 | }
21 | }
22 |
23 |
24 | public OnOffStruct this[int i]
25 | {
26 | set
27 | {
28 | _onCommand[i] = value.On;
29 | _offCommand[i] = value.Off;
30 | }
31 | }
32 |
33 | public void PushOn(int slot)
34 | {
35 | _onCommand[slot].Execute();
36 | _undoCommand = _offCommand[slot];
37 | }
38 |
39 | public void PushOff(int slot)
40 | {
41 | _offCommand[slot].Execute();
42 | _undoCommand = _onCommand[slot];
43 | }
44 |
45 | public void PushUndo()
46 | {
47 | _undoCommand.Execute();
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/CompositePattern/Program.cs:
--------------------------------------------------------------------------------
1 | namespace CompositePattern
2 | {
3 | static class Program
4 | {
5 | public static void Main()
6 | {
7 |
8 | var breakfast = new Menu("Breakfast", "Pancake House");
9 | var lunch = new Menu("Lunch", "Deli Diner");
10 | var dinner = new Menu("Dinner","Dinneroni");
11 |
12 | var dessert = new Menu("Dessert", "Ice Cream");
13 |
14 | var menu = new Menu("All", "McDonalds");
15 |
16 | breakfast.Add(new MenuItem("Waffles","Butterscotch waffles",140,false));
17 | breakfast.Add(new MenuItem("Corn Flakes","Kellogs",80,true));
18 |
19 | lunch.Add(new MenuItem("Burger", "Cheese and Onion Burger", 250, true));
20 | lunch.Add(new MenuItem("Sandwich", "Chicken Sandwich", 280, false));
21 |
22 | dinner.Add(new MenuItem("Pizza", "Cheese and Tomato Pizza", 210, true));
23 | dinner.Add(new MenuItem("Pasta", "Chicken Pasta", 280, false));
24 |
25 | dessert.Add(new MenuItem("Ice Cream", "Vanilla and Chocolate", 120, true));
26 | dessert.Add(new MenuItem("Cake", "Choclate Cake Slice",180, false));
27 |
28 | dinner.Add(dessert);
29 | menu.Add(breakfast);
30 | menu.Add(lunch);
31 | menu.Add(dinner);
32 |
33 | menu.Print();
34 |
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/StrategyPattern/Program.cs:
--------------------------------------------------------------------------------
1 | namespace Ducks
2 | {
3 | internal class Duck
4 | {
5 | private IQuackBehaviour _quacker;
6 | private IFlyBehaviour _flyer;
7 |
8 |
9 | public IQuackBehaviour Quacker {
10 | set
11 | {
12 | _quacker = value;
13 | }
14 | }
15 |
16 | public IFlyBehaviour Flyer
17 | {
18 | set
19 | {
20 | _flyer = value;
21 | }
22 | }
23 |
24 |
25 | protected void PerformQuack()
26 | {
27 | _quacker.Quack();
28 | }
29 |
30 | protected void PerformFly()
31 | {
32 | _flyer.Fly();
33 | }
34 | }
35 |
36 | internal class MallardDuck : Duck
37 | {
38 | public MallardDuck()
39 | {
40 | Flyer = new FlyNope();
41 | Quacker = new QuackNope();
42 | }
43 |
44 | public void Display()
45 | {
46 | PerformFly();
47 | PerformQuack();
48 | }
49 | }
50 |
51 | internal static class Program
52 | {
53 | private static void Main()
54 | {
55 | var mallard = new MallardDuck {Quacker = new QuackNormal()};
56 | mallard.Display();
57 | mallard.Flyer = new FlyWings();
58 | mallard.Display();
59 |
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/StrategyPattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("Ducks")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("Ducks")]
12 | [assembly: AssemblyCopyright("Copyright © 2017")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("1f52949e-3569-44ec-8c1c-870d5b263694")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/StatePattern/GumballMachine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace StatePattern
4 | {
5 | public class GumballMachine
6 | {
7 | public int Count { get; private set; }
8 |
9 | public IState SoldOutState;
10 | public IState NoQuarterState;
11 | public IState HasQuarterState;
12 | public IState SoldState;
13 | public IState WinnerState;
14 |
15 | public IState State { get; set; }
16 |
17 | public GumballMachine(int count)
18 | {
19 | Count = count;
20 | SoldOutState = new SoldOutState(this);
21 | NoQuarterState = new NoQuarterState(this);
22 | HasQuarterState = new HasQuarterState(this);
23 | SoldState = new SoldState(this);
24 | WinnerState = new WinnerState(this);
25 | if (Count > 0)
26 | {
27 | State = NoQuarterState;
28 | }
29 | }
30 |
31 | public void InsertQuarter()
32 | {
33 | State.InsertQuarter();
34 | }
35 |
36 | public void EjectQuarter()
37 | {
38 | State.EjectQuarter();
39 | }
40 |
41 | public void TurnCrank()
42 | {
43 | State.TurnCrank();
44 | State.Dispense();
45 | }
46 |
47 | public void ReleaseBall()
48 | {
49 | Console.WriteLine("A ball comes rolling down");
50 | if (Count == 0) return;
51 | Count--;
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/StatePattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("StatePattern")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("StatePattern")]
12 | [assembly: AssemblyCopyright("Copyright © 2017")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("974fe8e8-7379-4dcc-9d4f-763d60f5e708")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/AdapterPattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("AdapterPattern")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("AdapterPattern")]
12 | [assembly: AssemblyCopyright("Copyright © 2017")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("68b119d1-3527-4356-946f-cea179084c91")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/FactoryPattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("FactoryPattern")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("FactoryPattern")]
12 | [assembly: AssemblyCopyright("Copyright © 2017")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("d154b3a3-1c97-4b70-ad4f-dc4db8f52300")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/TemplatePattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("TemplatePattern")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("TemplatePattern")]
12 | [assembly: AssemblyCopyright("Copyright © 2017")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("fce8a301-ee20-42db-82dd-47ab0b569bc9")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/DecoratorPattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("DecoratorPattern")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("DecoratorPattern")]
12 | [assembly: AssemblyCopyright("Copyright © 2017")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("6e63bdd0-01a4-4a88-8a89-9b45d51b526d")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/SingletonPattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("SingletonPattern")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("SingletonPattern")]
12 | [assembly: AssemblyCopyright("Copyright © 2017")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("df749ac5-3277-45b6-b39e-61e7d842b1ba")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/CommandPattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 |
8 | [assembly: AssemblyTitle("CommandPattern")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("CommandPattern")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 |
21 | [assembly: ComVisible(false)]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 |
25 | [assembly: Guid("8f58357d-c54f-4c07-a951-8a93b0520187")]
26 |
27 | // Version information for an assembly consists of the following four values:
28 | //
29 | // Major Version
30 | // Minor Version
31 | // Build Number
32 | // Revision
33 | //
34 | // You can specify all the values or you can default the Build and Revision Numbers
35 | // by using the '*' as shown below:
36 | // [assembly: AssemblyVersion("1.0.*")]
37 |
38 | [assembly: AssemblyVersion("1.0.0.0")]
39 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/FacadePattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("FacadePattern")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("FacadePattern")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("c5cb5821-cc3b-4440-9cb9-a571a5d7b872")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/CompositePattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("CompositePattern")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("CompositePattern")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("0d5aa731-03f0-4cf6-aea3-254f06472911")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/IteratorPattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("IteratorPattern")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("IteratorPattern")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("a3b8c12f-5dac-4cea-b039-c2cbd7a5c9ad")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ObserverPattern/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ObserverPattern")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ObserverPattern")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("678581c4-15dc-4a01-93cd-76acbd5b7462")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/CommandPattern/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace CommandPattern
4 | {
5 | internal static class Program
6 | {
7 | private static void Main()
8 | {
9 | var remote = new RemoteControl(3);
10 |
11 |
12 | var bike = new Garage("Bike");
13 | var bikeDoorClose = new GarageDoorCloseCommand(bike);
14 | var bikeDoorOpen = new GarageDoorOpenCommand(bike);
15 |
16 | var car = new Garage("Car");
17 | var carDoorClose = new GarageDoorCloseCommand(car);
18 | var carDoorOpen = new GarageDoorOpenCommand(car);
19 |
20 | var garageButton = new OnOffStruct
21 | {
22 | On = bikeDoorOpen,
23 | Off = bikeDoorClose
24 | };
25 |
26 | remote[0] = garageButton;
27 | remote.PushOn(0);
28 | remote.PushUndo();
29 | remote.PushUndo();
30 | remote.PushOff(0);
31 |
32 |
33 | Console.WriteLine();
34 | var light = new Light("Hall");
35 |
36 | ICommand[] partyOn = {new LightOffCommand(light), bikeDoorOpen, carDoorOpen};
37 | ICommand[] partyOff = {new LightOnCommand(light), bikeDoorClose, carDoorClose};
38 |
39 |
40 | remote[2] = new OnOffStruct {On = new MacroCommand(partyOn), Off = new MacroCommand(partyOff)};
41 |
42 | try
43 | {
44 | remote.PushOn(2);
45 | Console.WriteLine();
46 | remote.PushOff(2);
47 | }
48 | catch (Exception)
49 | {
50 | Console.WriteLine("Oops");
51 | }
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/ObserverPattern/WeatherMonitor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ObserverPattern
4 | {
5 | sealed class WeatherMonitor : IObserver
6 | {
7 | private IDisposable _cancellation;
8 | private readonly string _name;
9 |
10 | public void Subscribe(WeatherSupplier provider)
11 | {
12 | _cancellation = provider.Subscribe(this);
13 | }
14 |
15 | public void Unsubscribe()
16 | {
17 | _cancellation.Dispose();
18 | }
19 |
20 | public WeatherMonitor(string name)
21 | {
22 | _name = name;
23 | }
24 |
25 | public void OnCompleted()
26 | {
27 | throw new NotImplementedException();
28 | }
29 |
30 | public void OnError(Exception error)
31 | {
32 | Console.WriteLine("Error has occured");
33 | }
34 |
35 | public void OnNext(Weather value)
36 | {
37 | Console.WriteLine(_name);
38 | if (_name.Contains("T"))
39 | {
40 | string op = $"| Temperature : {value.Temperature} Celsius |";
41 | Console.Write(op);
42 |
43 | }
44 | if (_name.Contains("P"))
45 | {
46 | string op = $"| Pressure : {value.Pressure} atm |";
47 | Console.Write(op);
48 | }
49 | if (_name.Contains("H"))
50 | {
51 | string op = $"| Humidity : {value.Humidity*100} % |";
52 | Console.Write(op);
53 | }
54 | if (!(_name.Contains("T") || _name.Contains("P") || _name.Contains("H")))
55 | {
56 | OnError(new Exception());
57 | }
58 | Console.WriteLine();
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/SingletonPattern/SingletonPattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {DF749AC5-3277-45B6-B39E-61E7D842B1BA}
8 | Exe
9 | SingletonPattern
10 | SingletonPattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/FacadePattern/FacadePattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {C5CB5821-CC3B-4440-9CB9-A571A5D7B872}
8 | Exe
9 | FacadePattern
10 | FacadePattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/CompositePattern/CompositePattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {0D5AA731-03F0-4CF6-AEA3-254F06472911}
8 | Exe
9 | CompositePattern
10 | CompositePattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/ObserverPattern/ObserverPattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {678581C4-15DC-4A01-93CD-76ACBD5B7462}
8 | Exe
9 | ObserverPattern
10 | ObserverPattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/TemplatePattern/TemplatePattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {FCE8A301-EE20-42DB-82DD-47AB0B569BC9}
8 | Exe
9 | TemplatePattern
10 | TemplatePattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/AdapterPattern/AdapterPattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {68B119D1-3527-4356-946F-CEA179084C91}
8 | Exe
9 | AdapterPattern
10 | AdapterPattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/CommandPattern/CommandPattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {8F58357D-C54F-4C07-A951-8A93B0520187}
8 | Exe
9 | CommandPattern
10 | CommandPattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/StrategyPattern/StrategyPattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {1F52949E-3569-44EC-8C1C-870D5B263694}
8 | Exe
9 | StrategyPattern
10 | StrategyPattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/DecoratorPattern/DecoratorPattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {6E63BDD0-01A4-4A88-8A89-9B45D51B526D}
8 | Exe
9 | DecoratorPattern
10 | DecoratorPattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/IteratorPattern/IteratorPattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {A3B8C12F-5DAC-4CEA-B039-C2CBD7A5C9AD}
8 | Exe
9 | IteratorPattern
10 | IteratorPattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/StatePattern/StatePattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {974FE8E8-7379-4DCC-9D4F-763D60F5E708}
8 | Exe
9 | StatePattern
10 | StatePattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/StatePattern/Legacy/GumballMachine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace StatePattern.Legacy
4 | {
5 | public class GumballMachine
6 | {
7 | private int _count;
8 | private State _state = State.NoQuarters;
9 |
10 | public GumballMachine(int count)
11 | {
12 | _count = count;
13 | }
14 |
15 | public void InsertQuarter()
16 | {
17 | switch (_state)
18 | {
19 | case State.NoQuarters:
20 | _state = State.HasQuarters;
21 | Console.WriteLine("Inserted a quarter");
22 | break;
23 | case State.Sold:
24 | Console.WriteLine("Please wait for current gumball to come out");
25 | break;
26 | case State.HasQuarters:
27 | Console.WriteLine("Can't add more quarters");
28 | break;
29 | case State.NoGumballs:
30 | Console.WriteLine("Out of Stock");
31 | break;
32 | default:
33 | throw new ArgumentOutOfRangeException();
34 | }
35 | }
36 |
37 | public void EjectQuarter()
38 | {
39 | switch (_state)
40 | {
41 | case State.NoQuarters:
42 | Console.WriteLine("Nothing to eject");
43 | break;
44 | case State.Sold:
45 | Console.WriteLine("Sorry, you have already turned the crank");
46 | break;
47 | case State.HasQuarters:
48 | Console.WriteLine("Ejecting..");
49 | _state = State.NoQuarters;
50 | break;
51 | case State.NoGumballs:
52 | Console.WriteLine("Can't eject, never accepted quarters");
53 | break;
54 | default:
55 | throw new ArgumentOutOfRangeException();
56 | }
57 | }
58 |
59 | public void TurnCrank()
60 | {
61 | switch (_state)
62 | {
63 | case State.NoQuarters:
64 | Console.WriteLine("Insert quarter First");
65 | break;
66 | case State.Sold:
67 | Console.WriteLine("Turning twice won't get you a gumball");
68 | break;
69 | case State.HasQuarters:
70 | Console.WriteLine("Getting gumball...");
71 | _state = State.Sold;
72 | Dispense();
73 | break;
74 | case State.NoGumballs:
75 | Console.WriteLine("Out of Stock");
76 | break;
77 | default:
78 | throw new ArgumentOutOfRangeException();
79 | }
80 | }
81 |
82 | private void Dispense()
83 | {
84 | switch (_state)
85 | {
86 | case State.NoQuarters:
87 | Console.WriteLine("You need to pay first");
88 | break;
89 | case State.Sold:
90 | Console.WriteLine("A Gumball comes rolling out");
91 | _count--;
92 | _state = _count == 0 ? _state = State.NoGumballs : State.NoQuarters;
93 | break;
94 | case State.HasQuarters:
95 | case State.NoGumballs:
96 | Console.WriteLine("Can't dispense");
97 | break;
98 | default:
99 | throw new ArgumentOutOfRangeException();
100 | }
101 | }
102 | }
103 | }
--------------------------------------------------------------------------------
/FactoryPattern/FactoryPattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {D154B3A3-1C97-4B70-AD4F-DC4DB8F52300}
8 | Exe
9 | FactoryPattern
10 | FactoryPattern
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/DesignPatterns.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26228.10
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObserverPattern", "ObserverPattern\ObserverPattern.csproj", "{678581C4-15DC-4A01-93CD-76ACBD5B7462}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StrategyPattern", "StrategyPattern\StrategyPattern.csproj", "{1F52949E-3569-44EC-8C1C-870D5B263694}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DecoratorPattern", "DecoratorPattern\DecoratorPattern.csproj", "{6E63BDD0-01A4-4A88-8A89-9B45D51B526D}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryPattern", "FactoryPattern\FactoryPattern.csproj", "{D154B3A3-1C97-4B70-AD4F-DC4DB8F52300}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingletonPattern", "SingletonPattern\SingletonPattern.csproj", "{DF749AC5-3277-45B6-B39E-61E7D842B1BA}"
15 | EndProject
16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandPattern", "CommandPattern\CommandPattern.csproj", "{8F58357D-C54F-4C07-A951-8A93B0520187}"
17 | EndProject
18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdapterPattern", "AdapterPattern\AdapterPattern.csproj", "{68B119D1-3527-4356-946F-CEA179084C91}"
19 | EndProject
20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FacadePattern", "FacadePattern\FacadePattern.csproj", "{C5CB5821-CC3B-4440-9CB9-A571A5D7B872}"
21 | EndProject
22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemplatePattern", "TemplatePattern\TemplatePattern.csproj", "{FCE8A301-EE20-42DB-82DD-47AB0B569BC9}"
23 | EndProject
24 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IteratorPattern", "IteratorPattern\IteratorPattern.csproj", "{A3B8C12F-5DAC-4CEA-B039-C2CBD7A5C9AD}"
25 | EndProject
26 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompositePattern", "CompositePattern\CompositePattern.csproj", "{0D5AA731-03F0-4CF6-AEA3-254F06472911}"
27 | EndProject
28 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StatePattern", "StatePattern\StatePattern.csproj", "{974FE8E8-7379-4DCC-9D4F-763D60F5E708}"
29 | EndProject
30 | Global
31 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
32 | Debug|Any CPU = Debug|Any CPU
33 | Release|Any CPU = Release|Any CPU
34 | EndGlobalSection
35 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
36 | {678581C4-15DC-4A01-93CD-76ACBD5B7462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {678581C4-15DC-4A01-93CD-76ACBD5B7462}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {678581C4-15DC-4A01-93CD-76ACBD5B7462}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {678581C4-15DC-4A01-93CD-76ACBD5B7462}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {1F52949E-3569-44EC-8C1C-870D5B263694}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {1F52949E-3569-44EC-8C1C-870D5B263694}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {1F52949E-3569-44EC-8C1C-870D5B263694}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {1F52949E-3569-44EC-8C1C-870D5B263694}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {6E63BDD0-01A4-4A88-8A89-9B45D51B526D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {6E63BDD0-01A4-4A88-8A89-9B45D51B526D}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {6E63BDD0-01A4-4A88-8A89-9B45D51B526D}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {6E63BDD0-01A4-4A88-8A89-9B45D51B526D}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {D154B3A3-1C97-4B70-AD4F-DC4DB8F52300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {D154B3A3-1C97-4B70-AD4F-DC4DB8F52300}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {D154B3A3-1C97-4B70-AD4F-DC4DB8F52300}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {D154B3A3-1C97-4B70-AD4F-DC4DB8F52300}.Release|Any CPU.Build.0 = Release|Any CPU
52 | {DF749AC5-3277-45B6-B39E-61E7D842B1BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {DF749AC5-3277-45B6-B39E-61E7D842B1BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {DF749AC5-3277-45B6-B39E-61E7D842B1BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {DF749AC5-3277-45B6-B39E-61E7D842B1BA}.Release|Any CPU.Build.0 = Release|Any CPU
56 | {8F58357D-C54F-4C07-A951-8A93B0520187}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57 | {8F58357D-C54F-4C07-A951-8A93B0520187}.Debug|Any CPU.Build.0 = Debug|Any CPU
58 | {8F58357D-C54F-4C07-A951-8A93B0520187}.Release|Any CPU.ActiveCfg = Release|Any CPU
59 | {8F58357D-C54F-4C07-A951-8A93B0520187}.Release|Any CPU.Build.0 = Release|Any CPU
60 | {68B119D1-3527-4356-946F-CEA179084C91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
61 | {68B119D1-3527-4356-946F-CEA179084C91}.Debug|Any CPU.Build.0 = Debug|Any CPU
62 | {68B119D1-3527-4356-946F-CEA179084C91}.Release|Any CPU.ActiveCfg = Release|Any CPU
63 | {68B119D1-3527-4356-946F-CEA179084C91}.Release|Any CPU.Build.0 = Release|Any CPU
64 | {C5CB5821-CC3B-4440-9CB9-A571A5D7B872}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
65 | {C5CB5821-CC3B-4440-9CB9-A571A5D7B872}.Debug|Any CPU.Build.0 = Debug|Any CPU
66 | {C5CB5821-CC3B-4440-9CB9-A571A5D7B872}.Release|Any CPU.ActiveCfg = Release|Any CPU
67 | {C5CB5821-CC3B-4440-9CB9-A571A5D7B872}.Release|Any CPU.Build.0 = Release|Any CPU
68 | {FCE8A301-EE20-42DB-82DD-47AB0B569BC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69 | {FCE8A301-EE20-42DB-82DD-47AB0B569BC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
70 | {FCE8A301-EE20-42DB-82DD-47AB0B569BC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
71 | {FCE8A301-EE20-42DB-82DD-47AB0B569BC9}.Release|Any CPU.Build.0 = Release|Any CPU
72 | {A3B8C12F-5DAC-4CEA-B039-C2CBD7A5C9AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
73 | {A3B8C12F-5DAC-4CEA-B039-C2CBD7A5C9AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
74 | {A3B8C12F-5DAC-4CEA-B039-C2CBD7A5C9AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
75 | {A3B8C12F-5DAC-4CEA-B039-C2CBD7A5C9AD}.Release|Any CPU.Build.0 = Release|Any CPU
76 | {0D5AA731-03F0-4CF6-AEA3-254F06472911}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77 | {0D5AA731-03F0-4CF6-AEA3-254F06472911}.Debug|Any CPU.Build.0 = Debug|Any CPU
78 | {0D5AA731-03F0-4CF6-AEA3-254F06472911}.Release|Any CPU.ActiveCfg = Release|Any CPU
79 | {0D5AA731-03F0-4CF6-AEA3-254F06472911}.Release|Any CPU.Build.0 = Release|Any CPU
80 | {974FE8E8-7379-4DCC-9D4F-763D60F5E708}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
81 | {974FE8E8-7379-4DCC-9D4F-763D60F5E708}.Debug|Any CPU.Build.0 = Debug|Any CPU
82 | {974FE8E8-7379-4DCC-9D4F-763D60F5E708}.Release|Any CPU.ActiveCfg = Release|Any CPU
83 | {974FE8E8-7379-4DCC-9D4F-763D60F5E708}.Release|Any CPU.Build.0 = Release|Any CPU
84 | EndGlobalSection
85 | GlobalSection(SolutionProperties) = preSolution
86 | HideSolutionNode = FALSE
87 | EndGlobalSection
88 | EndGlobal
89 |
--------------------------------------------------------------------------------