public static void Implementasi() { Pecel pecel; bool lagiKolesterol = false; if (lagiKolesterol == false) { pecel = new Bebek(); } else { pecel = new Ayam(); } }
public Pecel BikinPecel(string TipePecel) // disini proses pembuatan object pecel sesuai pilihan terjadi { Pecel pecel = null; if (TipePecel == "ayam") { pecel = new Ayam(); } else if (TipePecel == "bebek") { pecel = new Bebek(); } return(pecel); }
static void Main(string[] args) { /*Hewan hewan; * * hewan = new Kucing(); * hewan.bunyi(); * * Console.WriteLine(); * hewan = new Ayam(); * hewan.bunyi(); * * Console.ReadKey();*/ IHewan hewan; hewan = new Kucing(); hewan.bunyi(); Console.WriteLine(); hewan = new Ayam(); hewan.bunyi(); Console.ReadKey(); }