static void Main(string[] args) { var plates = new List <IPlateNG>(); plates.Add(new HugePlate()); plates.Add(new SmallPlate()); IPlateNG aPlate = plates[0]; IWaffle aWaffle = aPlate.GetWaffle(); Console.WriteLine(aWaffle.Eat()); IPlate <FalafelWaffle> aSmallPlate = (SmallPlate)plates[1]; FalafelWaffle aFalafel = aSmallPlate.GetMyWaffle(); Console.WriteLine(aFalafel.Dinner()); Console.ReadKey(); }
static void Main(string[] args) { // The list cannot work with the IPlate<IWaffle> anymore. So here comes IPlateNG to the rescue var plates = new List <IPlateNG>(); plates.Add(new HugePlate()); plates.Add(new SmallPlate()); IPlateNG aPlate = plates[0]; // And instead of calling to the GetMyWaffle method we can call to the GetWaffle in this case IWaffle aWaffle = aPlate.GetWaffle(); Console.WriteLine(aWaffle.Eat()); IPlate <FalafelWaffle> aSmallPlate = (SmallPlate)plates[1]; FalafelWaffle aFalafel = aSmallPlate.GetMyWaffle(); Console.WriteLine(aFalafel.Dinner()); }