static void Main(string[] args) { // Yöntem 1 Creator1 RaporCreator = new Creator1(); IRapor rapor = RaporCreator.RaporFactory(RaporTip.Grafik); rapor.Olustur(); rapor = RaporCreator.RaporFactory(RaporTip.Tablo); rapor.Olustur(); Console.WriteLine(""); // Yöntem 2 IRaporCreator[] Creators = { new CreatorTabloRapor() , new CreatorGrafikRapor() }; foreach (IRaporCreator item in Creators) { IRapor _rapor = item.CreateRapor(); _rapor.Olustur(); } Console.ReadKey(); }
/// <summary> /// Factory Method /// </summary> /// <param name="raporTip">Rapor tipi</param> /// <returns>İstenilen tipdeki rapor referansı (product)</returns> public IRapor RaporFactory(RaporTip raporTip) { IRapor rapor = null; switch (raporTip) { case RaporTip.Tablo: rapor = new RaporTablo(); break; case RaporTip.Grafik: rapor = new RaporGrafik(); break; default: break; } return(rapor); }
void RaporListele() { ListelemeFabrikası listelemeFabrikası = new ListelemeFabrikası(); //ListelemeFabrikası classı için nesne oluşturuldu IRapor liste = listelemeFabrikası.RaporListeOlustur("RaporListele"); //oluşturulan nesne ile Method ismine göre işlem yapıyor if (RaporUrunTipi.Text == "Hepsi") { raporDGV.DataSource = liste.Listele(UserIdLabel.Text, RaporUrunAd.Text, KucukTarihDTP.Text, BuyukTarihDTP.Text, RaporUrunTipi.Text); } else if (RaporUrunTipi.Text == "Sattığım Ürünler") { //Interface nesnesine göre istenilen bilgiler yollanıyor raporDGV.DataSource = liste.Listele(UserIdLabel.Text, RaporUrunAd.Text, KucukTarihDTP.Text, BuyukTarihDTP.Text, RaporUrunTipi.Text); } else { raporDGV.DataSource = liste.Listele(UserIdLabel.Text, RaporUrunAd.Text, KucukTarihDTP.Text, BuyukTarihDTP.Text, RaporUrunTipi.Text); } this.raporDGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; //dataGridView'ın boyutlarına göre tabloların boyutlarını ayarlama }