Example #1
0
        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);
        }
Example #3
0
        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();
        }