<repo_name>tarr3ga/Design-Patterns<file_sep>/FactoryPattern/NYStyleCheesePizza.cs
﻿namespace FactoryPattern
{
    class NYStyleCheesePizza : Pizza
    {

        public NYStyleCheesePizza()
        {
            this.type = "New York style cheese pizza";
            this.dough = "Thin crust dough";
            this.sauce = "Marinara sauce";
            this.toppings.Add("Cheese");

            this.prepare();
            this.bake();
            this.cut();
            this.box();
        }
    }
}
<file_sep>/FactoryPattern/ChicagoStyleCheesePizza.cs
﻿namespace FactoryPattern
{
    class ChicagoStyleCheesePizza : Pizza
    {
        public ChicagoStyleCheesePizza()
        {
            this.type = "Chicago style pepperoni pizza";
            this.dough = "Deep diah crust dough";
            this.sauce = "Plum tomato sauce";
            this.toppings.Add("Cheese");

            this.prepare();
            this.bake();
            this.cut();
            this.box();
        }
    }
}
<file_sep>/FactoryPattern/ChicagoPizzaStore.cs
﻿namespace FactoryPattern
{
    class ChicagoPizzaStore : PizzaStore
    {
        protected override Pizza createPizza(string item)
        {
            if (item.Equals("Cheese"))
                return new ChicagoStyleCheesePizza();
            else if (item.Equals("Supreme"))
                return new ChicagoStyleSupremePizza();
            else return null;
        }
    }
}
<file_sep>/FactoryPattern/NYStylePepperoniPizza.cs
﻿namespace FactoryPattern
{
    class NYStylePepperoniPizza : Pizza
    {
        public NYStylePepperoniPizza()
        {
            this.type = "New York style pepperoni pizza";
            this.dough = "Thin crust dough";
            this.sauce = "Marinara sauce";
            this.toppings.Add("Cheese");
            this.toppings.Add("Pepperoni");

            this.prepare();
            this.bake();
            this.cut();
            this.box();
        }
    }
}
<file_sep>/ObserverPattern/IObserver.cs
﻿namespace ObserverPattern
{
    public interface IObserver
    {
        void update(int temp, int humidity, int pressure);
    }
}
<file_sep>/ObserverPattern/WeatherData.cs
﻿using System.Collections.Generic;

namespace ObserverPattern
{
    public class WeatherData : ISubject
    {
        private List<IObserver> observers = new List<IObserver>();
        private int temperature;
        private int humidity;
        private int pressure;

        public int Temperature { get => temperature; set => temperature = value; }
        public int Humidity { get => humidity; set => humidity = value; }
        public int Pressure { get => pressure; set => pressure = value; }

        public WeatherData()
        {

        }

        public WeatherData(int temperature, int humidity, int pressure)
        {
            this.temperature = temperature;
            this.humidity = humidity;
            this.pressure = pressure;

            measurmentsChanged();
        }

        public void setMeasurements(int temperature, int humidity, int pressure)
        {
            this.temperature = temperature;
            this.humidity = humidity;
            this.pressure = pressure;
            measurmentsChanged();
        }

        public void measurmentsChanged()
        {
            notifyObserver();
        }

        public void registerObserver(IObserver o)
        {
            observers.Add(o);
        }

        public void removeObserver(IObserver o)
        {
            int i = observers.IndexOf(o);

            if (i >= 0)
                observers.RemoveAt(i);
        }

        public void notifyObserver()
        {
            foreach(IObserver o in observers)
            {
                o.update(temperature, humidity, pressure);
            }
        }
    }
}
<file_sep>/FactoryPattern/ChicagoStyleSupremePizza.cs
﻿namespace FactoryPattern
{
    class ChicagoStyleSupremePizza : Pizza
    {
        public ChicagoStyleSupremePizza()
        {
            this.type = "Chicago style supreme pizza";
            this.dough = "Deep diah crust dough";
            this.sauce = "Plum tomato sauce";
            this.toppings.Add("Cheese");
            this.toppings.Add("Peperoni");
            this.toppings.Add("Sauage");
            this.toppings.Add("Mushrooms");
            this.toppings.Add("Green peppers");
            this.toppings.Add("Black Olives");

            this.prepare();
            this.bake();
            this.cut();
            this.box();
        }
    }
}
<file_sep>/ObserverPattern/Program.cs
﻿namespace ObserverPattern
{
    class Program
    {
        static void Main(string[] args)
        {
            WeatherData data = new WeatherData();

            CurrentConditions current = new CurrentConditions(data);
            Forecast forecast = new Forecast(data);
            Statitstics statistics = new Statitstics(data);

            data.setMeasurements(75, 54, 2);
            data.setMeasurements(80, 48, 3);
            data.setMeasurements(65, 40, 2);
        }
    }
}
<file_sep>/FactoryPattern/NYStyleClamPizza.cs
﻿namespace FactoryPattern
{
    class NYStyleClamPizza : Pizza
    {
        public NYStyleClamPizza()
        {
            this.type = "New York style clam pizza";
            this.dough = "Thin crust dough";
            this.sauce = "Fish sauce";
            this.toppings.Add("Cheese");
            this.toppings.Add("Clams");
            this.toppings.Add("More clams");

            this.prepare();
            this.bake();
            this.cut();
            this.box();
        }
    }
}
<file_sep>/FactoryPattern/Pizza.cs
﻿using System;
using System.Collections.Generic;

namespace FactoryPattern
{
    public abstract class Pizza
    {
        protected string type;
        protected string dough;
        protected string sauce;
        protected List<string> toppings = new List<string>();

        public Pizza createPizza(string type)
        {
            this.type = type;

            return this;
        }

        public void prepare() {
            Console.WriteLine("Preparing " + type);
            Console.WriteLine("Tossing dough...");
            Console.WriteLine("Adding " + sauce + " sauce...");
            Console.WriteLine("Adding toppings...");
            foreach(string s in toppings)
            {
                Console.WriteLine(s);
            }
        }

        public void bake() {
            Console.WriteLine("Baking for 20 minutes at 350...");
        }

        public void cut() {
            Console.WriteLine("Cutting pizza...");
        }

        public void box() {
            Console.WriteLine("Boxing pizza...");
            Console.WriteLine("");
        }
    }
}
<file_sep>/FactoryPattern/Program.cs
﻿namespace FactoryPattern
{
    class Program
    {
        static void Main(string[] args)
        {
            PizzaStore myStore = new NYPizzaStore();
            myStore.orderPizza("Pepperoni");

            myStore = new ChicagoPizzaStore();
            myStore.orderPizza("Supreme");
        }
    }
}
<file_sep>/FactoryPattern/NYStyleVeggiePizza.cs
﻿namespace FactoryPattern
{
    class NYStyleVeggiePizza : Pizza
    {
        public NYStyleVeggiePizza()
        {
            this.type = "New York style veggie pizza";
            this.dough = "Thin crust dough";
            this.sauce = "Marinara sauce";
            this.toppings.Add("Cheese");
            this.toppings.Add("Tomatoes");
            this.toppings.Add("Cucumber");
            this.toppings.Add("Olives");
            this.toppings.Add("Eggpant");
            this.toppings.Add("Feta Cheese");

            this.prepare();
            this.bake();
            this.cut();
            this.box();
        }
    }
}
<file_sep>/SingletonPattern/Program.cs
﻿using System;

namespace SingletonPattern
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }


    public sealed class SampleSingleton : IDisposable
    {
        private bool _disposed;
        public static volatile SampleSingleton _instance;
        public static readonly object _synLock = new object(); 

        private SampleSingleton()
        {

        }

        public static SampleSingleton Instance
        {
            get
            {
                if (Instance != null)
                    return _instance;

                lock (_synLock)
                {
                    if(_instance == null)
                    {
                        _instance = new SampleSingleton();
                    }
                }
                return _instance;
            }
        }

        public int SomeValue { get; set; }

        public void Dispose()
        {
            Dispose(true);

            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (_disposed)
                return;

            if (disposing)
            {
                _instance = null;
            }
        }
    }
}
<file_sep>/ObserverPattern/Displays/Forecast.cs
﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ObserverPattern
{
    class Forecast : IObserver, IDisplayElement
    {
        private int temperature;
        private int humidity;
        private ISubject weatherData;

        public Forecast(ISubject weatherData)
        {
            this.weatherData = weatherData;
            weatherData.registerObserver(this);
        }

        public void display()
        {
            Console.WriteLine("Forcast: " + temperature + "F Degrees and " + humidity + "% Humidity");
        }

        public void update(int temp, int humidity, int pressure)
        {
            this.temperature = temp;
            this.humidity = humidity;
            display();
        }
    }
}
