static void Main(string[] args) { for (int i = 0; i < 100; i++) { DogBase dogFactory = DogFactory.GedDog(GetRandDogBreed()); Console.WriteLine(dogFactory.GetDogBreed()); } }
public static DogBase GedDog(DogBreed dogBreed) { DogBase dog = null; if (dogBreedDict.ContainsKey(dogBreed)) { dog = dogBreedDict.First(db => db.Key == dogBreed).Value; } else { switch (dogBreed) { case DogBreed.Dalmatian: dog = new Dalmatian(); break; case DogBreed.GoldenRetriever: dog = new GoldenRetriever(); break; case DogBreed.Labrador: dog = new Labrador(); break; case DogBreed.Pinscher: dog = new Pinscher(); break; case DogBreed.Poodle: dog = new Poodle(); break; } Console.WriteLine($"{dogBreed} Created"); dogBreedDict.Add(dogBreed, dog); } return(dog); }
static void Main(string[] args) { var utahraptor = new Utahraptor(); var triceratops = new Triceratops(); var stygimoloch = new Stygimoloch(); var stegosaurus = new Stegosaurus(); var dinos = new DinoBase[] { utahraptor, triceratops, stegosaurus, stygimoloch }; var boxer = new Boxer(); var rotweiler = new Rotweiler(); var chihuahua = new Chihuahua(); var dogs = new DogBase[] { boxer, rotweiler, chihuahua }; Console.WriteLine("Do You want to learn about dogs or dinosaurs? (dog/dino)"); string answer = Console.ReadLine(); if (answer == "dino") { foreach (var dino in dinos) { dino.PrintDinos(); dino.Carnivore(); Console.ReadLine(); } } else if (answer == "dog") { foreach (var dog in dogs) { dog.PrintDogs(); dog.Loyalty(); Console.ReadLine(); } } }