Example #1
0
        static void Main(string[] args)
        {
            //
            // OLD MACDONALD
            //

            ISingable[] singables = new ISingable[]
            {
                new Cow(), new Chicken(), new Pig(), new Tractor()
            };

            foreach (ISingable singable in singables)
            {
                Console.WriteLine("Old MacDonald had a farm, ee ay ee ay oh!");
                Console.WriteLine("And on his farm he had a " + singable.Name + ", ee ay ee ay oh!");
                Console.WriteLine("With a " + singable.Sound + " " + singable.Sound + " here");
                Console.WriteLine("And a " + singable.Sound + " " + singable.Sound + " there");
                Console.WriteLine("Here a " + singable.Sound + " there a " + singable.Sound + " everywhere a " + singable.Sound + " " + singable.Sound);
                Console.WriteLine();
            }

            ISellable[] sellables = new ISellable[]
            {
                new Cow(), new Pig(), new Egg()
            };

            foreach (ISellable sellable in sellables)
            {
                Console.WriteLine("Step right up and get your " + sellable.Name);
                Console.WriteLine("Only $" + sellable.Price);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            //
            // OLD MACDONALD
            //

            //collection of type FarmAnimal - can include any type derived from FarmAnimal as well
            ISingable[] singingFarmCollection = new ISingable[] { new Cow(), new Chicken(), new Sheep(), new Tractor() };

            // RidingTractor johnDeere = new RidingTractor();
            //  johnDeere.Mow();
            //cant change because protected set
            //johnDeere.NumberOfTires = 4;

            //interfaces cant be instantiated
            //ISingable test = new ISingable();
            //
            //FarmAnimal animal1 = new FarmAnimal("generic animal");

            foreach (ISingable farmSinger in singingFarmCollection)
            {
                Console.WriteLine("Old MacDonald had a farm, ee ay ee ay oh!");
                Console.WriteLine("And on his farm he had a " + farmSinger.Name + ", ee ay ee ay oh!"); //property from Base Class - not polymorphism
                Console.WriteLine("With a " + farmSinger.MakeSound() + " " + farmSinger.MakeSound() + " here");
                Console.WriteLine("And a " + farmSinger.MakeSound(2) + "there");                        //calling overloaded MakeSound method in FarmAnimal
                Console.WriteLine("Here a " + farmSinger.MakeSound() + " there a " + farmSinger.MakeSound() + " everywhere a " + farmSinger.MakeSound() + " " + farmSinger.MakeSound());
                Console.WriteLine();
            }
        }
Example #3
0
 private static void SingTheVerse(ISingable item)
 {
     Console.WriteLine("And on his farm there was a " + item.Name + " ee ay ee ay oh");
     Console.WriteLine("With a " + item.MakeSoundTwice() + " here and a " + item.MakeSoundTwice() + " there");
     Console.WriteLine("Here a " + item.MakeSoundOnce() + ", there a " + item.MakeSoundOnce() + " everywhere a " + item.MakeSoundTwice());
     Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh");
     Console.WriteLine();
 }
Example #4
0
        static void SingVerse(ISingable singable)
        {
            //
            // OLD MACDONALD
            //
            Console.WriteLine("Old MacDonald had a farm. ee aye ee aye oh");

            Console.WriteLine($"And on his farm there was a {singable.Name}. ee ay ee ay oh");
            Console.WriteLine($"With a {singable.MakeSoundTwice()} here and a {singable.MakeSoundTwice()} there.");
            Console.WriteLine($"Here a {singable.MakeSoundOnce()}, there a {singable.MakeSoundOnce()}, everywhere a {singable.MakeSoundTwice()}.");
            Console.WriteLine($"Old Macdonald had a farm. ee aye ee aye oh");
            Console.WriteLine();
        }
        static void Main(string[] args)
        {
            //
            // OLD MACDONALD
            //

            Cow sleepy = new Cow("Sleepy");

            sleepy.Sleep();
            Cat cat = new Cat("Cosmic Creepers");

            cat.Sleep();
            Jersey jersey = new Jersey();
            Cat    felix  = new Cat("Felix");

            Console.WriteLine(sleepy.Eat());
            Console.WriteLine(cat.Eat());
            ISingable[] singables = new ISingable[]
            {
                new Cow("Henry"), new Chicken(), new Pig(), new Tractor(), new Cow("Earl"), sleepy, cat, jersey, felix
            };

            ((FarmAnimal)singables[2]).Sleep();
            foreach (ISingable singable in singables)
            {
                Console.WriteLine("Old MacDonald had a farm, ee ay ee ay oh!");
                Console.WriteLine("And on his farm he had a " + singable.Name + ", ee ay ee ay oh!");
                Console.WriteLine("With a " + singable.Sound + " " + singable.Sound + " here");
                Console.WriteLine("And a " + singable.Sound + " " + singable.Sound + " there");
                Console.WriteLine("Here a " + singable.Sound + " there a " + singable.Sound + " everywhere a " + singable.Sound + " " + singable.Sound);
                Console.WriteLine();
            }

            ISellable[] sellables = new ISellable[]
            {
                new Cow("Henry"), new Pig(), new Egg()
            };

            foreach (ISellable sellable in sellables)
            {
                Console.WriteLine("Step right up and get your " + sellable.Name);
                Console.WriteLine("Only $" + sellable.Price);
            }
        }
Example #6
0
 public static void Sing(ISingable thingThatSings)
 {
     thingThatSings.MakeSound();
 }