Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Flash     flash     = new Flash("Speedy", 16, 220);
            SpiderMan spiderman = new SpiderMan("Toby", 28, 1000);
            SuperMan  superman  = new SuperMan("Clark Kent", 200, "Faster Than a Bullet");

            Console.WriteLine(flash.ToString());
            ActivateSuperhero(flash);
            Console.WriteLine(spiderman.ToString());
            ActivateSuperhero(spiderman);
            Console.WriteLine(superman.ToString());
            ActivateSuperhero(superman);

            IdentifyHero(spiderman);
            IdentifyHero(superman);
            IdentifyHero(flash);
            Console.WriteLine();

            GetMoreHeroData(flash);
            GetMoreHeroData(superman);
            GetMoreHeroData(spiderman);
            Console.WriteLine();

            CreateHero(flash);
            CreateHero(spiderman);
            CreateHero(superman);
        }
Exemplo n.º 2
0
        static void CreateHero(ISuperHero seHero)
        {
            if (seHero.GetType() == typeof(Flash))
            {
                Flash flash1 = new Flash("New Flash", 18, 480);
                Console.WriteLine("*** New object **");
                Console.WriteLine(flash1.ToString());
            }

            if (seHero.GetType() == typeof(SuperMan))
            {
                SuperMan super1 = new SuperMan("New Clark", 58, "120");
                Console.WriteLine("*** New object **");
                Console.WriteLine(super1.ToString());
            }
            else if (seHero.GetType() == typeof(SpiderMan))
            {
                SpiderMan spider1 = new SpiderMan("New Spider", 44, 100);
                Console.WriteLine("*** New object **");
                Console.WriteLine(spider1.ToString());
            }
        }