static void Main(string[] args) { Console.WriteLine("\tINTERFACE VS ABSTRACT CLASS\n\t" + new string('-', 27)); /* * IAlcohol[] alcoholsDrinks = new IAlcohol[3] * * alcoholsDrinks[0] = new StrongDrink("Tatratea"); * alcoholsDrinks[1] = new FizzyAlcohol("Somersby"); * ... * It's boring! * || It's the same ( Ugyan az ) \/ */ IAlcohol[] alcoholsDrinks = new IAlcohol[] { new StrongDrink("Tatratea"), // interface típusú gyűjteményt tudunk itt is létrehozni new FizzyAlcohol("Somersby"), // csak úgy, mint (abs.) ősosztály esetén new Juice() { Name = "Bambi" } }; // polimorfizmus működik interface-k esetén is // hiszen ezen esetben CSAK késői kötéssel működnek a metódusok // (ha belegondolunk, korai kötés nem is működne, hiszen nincs az "ősben" kifejtve a metódus...) for (int i = 0; i < alcoholsDrinks.Length; i++) { Console.WriteLine(alcoholsDrinks[i]); // override ToString() >> We can costumize ToString ( Testre tudjuk szabni, hogy hogyan irassuk ki a dolgokat ) if (alcoholsDrinks[i] is Juice) { Console.WriteLine("NON-ALCOHOL DRINKS\n" + new string('_', 18)); Console.BackgroundColor = ConsoleColor.Green; Console.WriteLine((alcoholsDrinks[i] as Juice).Name); Console.ResetColor(); } } Console.ReadLine(); }
public Sale(IAlcohol product, Client client, double count) { this.product = product; this.client = client; this.count = count; }
public string GetAlcoholWithVoltage() { IAlcohol alcohol = _alcoholFactory.CreateBeer(); return(string.Format("Dostałeś {0} mający {1}%", alcohol.Name, alcohol.Voltage)); }