public static ISuperhero GetSuperhero(SuperheroUniverse universe) { ISuperhero superhero = null; if (universe.Universe.Equals(SuperheroUniverse.Marvel.Universe)) { if (marvelHero == null) { marvelHero = new MarvelHero(); } superhero = marvelHero; } if (universe.Universe.Equals(SuperheroUniverse.Dc.Universe)) { if (dcHero == null) { dcHero = new DcHero(); } superhero = dcHero; } return(superhero); }
public SuperheroAdapter(ISuperhero hero) { _hero = hero; _fly = _hero.Fly(); _shoot = _hero.Shoot(); _walls = _hero.GoThrougWalls(); }
static void IdentifyHero(ISuperhero d) { if (d is SuperMan) { Console.WriteLine("superman detected"); } else if (d is SpidreMan) { Console.WriteLine("spidrman detected"); } else { Console.WriteLine("Flash detected"); } }
static void Main(string[] args) { _superheroService = new SuperheroService(); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine("\nAdding superheroes from seed data...\n"); _superheroService.AddSuperheroesAysncFromSeedData().Wait(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\nListing Marvel superheroes and their superpowers:\n"); ISuperhero superhero = SuperheroFactory.GetSuperhero(SuperheroUniverse.Marvel); ListSuperheroes(superhero.Superheroes); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nListing Dc superheroes and their superpowers:\n"); superhero = SuperheroFactory.GetSuperhero(SuperheroUniverse.Dc); ListSuperheroes(superhero.Superheroes); Console.Read(); }
static void Main(string[] args) { Flash a = new Flash("gary", 23, 5); SpidreMan b = new SpidreMan("peter", 21, 120); SuperMan c = new SuperMan("clark", 28, 530); Console.WriteLine(a); Console.WriteLine(b); ISuperhero[] allheroes = new ISuperhero[] { new Flash("gary", 23, 5), new SpidreMan("peter", 21, 120), new SuperMan("clark", 28, 530), }; ActiveHero(a); IdentifyHero(b); foreach (ISuperhero i in allheroes) { ActiveHero(i); Console.WriteLine(i); } }
static void ActiveHero(ISuperhero D) { }