C# Abstract Factory Method Design Pattern Örneği

 C# dilinde Abstract Factory Metot Tasarım Deseni için örnek bir kod hazırladım.



using System;


namespace TekstilFabrikasi

{

public interface IPantolon

{

string PantolonEkle();

}

public interface IGomlek

{

string GomlekEkle();

}

    public class Pantolon : IPantolon

    {

        public string PantolonEkle()

        {

            return "Pantolon";

        }

    }

    public class Gomlek : IGomlek

    {

        public string GomlekEkle()

        {

            return "Gömlek";

        }

    }

public interface ICeket

{

string CeketEkle();

}

public class Ceket : ICeket

    {

        public string CeketEkle()

        {

            return "Ceket";

        }

    }


    public interface IElbiseFactory{

IPantolon PantolonYap();

IGomlek GomlekYap();

ICeket CeketYap();

string KumasTipi();

string Mevsimi();

}


    public class Yazlik : IElbiseFactory

    {

        public string KumasTipi()

        {

           return "Ürünler Keten Kumaştan İmal Edilmiştir.";

        }

public string Mevsimi()

        {

           return "Yaz Sezonu İçin Takım";

        }


        public IPantolon PantolonYap()

        {

            return new Pantolon();

        }

public IGomlek GomlekYap()

        {

            return new Gomlek();

        }

public ICeket CeketYap()

        {

            return new Ceket();

        }

    }



public class TakimOlustur{

private readonly IPantolon _pantolon;

private readonly IGomlek _gomlek;

private readonly ICeket _ceket;

private readonly string _kumasTipi;

private readonly string _mevsim;


public TakimOlustur(IElbiseFactory elbiseFactory){

_pantolon = elbiseFactory.PantolonYap();

_gomlek = elbiseFactory.GomlekYap();

_kumasTipi = elbiseFactory.KumasTipi();

_mevsim = elbiseFactory.Mevsimi();

_ceket = elbiseFactory.CeketYap();

}

public void TakimiSun()

{

Console.WriteLine(_mevsim);

Console.WriteLine(_kumasTipi);

Console.WriteLine(_pantolon.PantolonEkle());

Console.WriteLine(_gomlek.GomlekEkle());

Console.WriteLine(_ceket.CeketEkle());

}

}


public class Program

{

public static void Main(string[] args){

IElbiseFactory yazlik = new Yazlik();

TakimOlustur takimSiparis = new TakimOlustur(yazlik);

takimSiparis.TakimiSun();


}

}

}

Yorumlar

Bu blogdaki popüler yayınlar

Javascript ile veriyi bir alt satıra nasıl yazdırabiliriz?

JQuery Toggle Açılır Kapanır Menü

C# Field Nedir?