public static void SwimmerTest(String[] args) { Swimmer johan = new Swimmer("Johan"); Swimmer magnus = new Swimmer("Magnus", new BathingSuit()); johan.SetSuit(new BathingSuit()); magnus.SetSuit(null); ProfessionalSwimmer eric = new ProfessionalSwimmer("Eric", new BathingSuit()); // Följande rad borde ge kompileringsfel eftersom man // inte får skapa ProfSwimmers utan baddräkt! ProfessionalSwimmer simon = new ProfessionalSwimmer("Simon"); // Denna rad borde inte påverka eric alls. eric.SetSuit(null); List <Swimmer> swimmers = new List <Swimmer>(); swimmers.Add(johan); swimmers.Add(new YoungSwimmer("Christoffer", new BathingSuit())); foreach (Swimmer sw in swimmers) { sw.Swim(); } // Följande kommer ut i terminalen: // Splish splash - it's so fun in the bath! // Splish splash - it's so fun in the bath! foreach (Swimmer sw in swimmers) { sw.Swim(); } // Följande kommer ut i terminalen: // Splish splash - it's so fun in the bath! // I'm so tired - time to get out. }
public static void BubblePoolTest(String[] args) { Console.WriteLine("----- BubblePoolTest start"); BubblePool newPool = new BubblePool(5); Swimmer johan = new Swimmer(); for (int i = 4; (i > 0); i--) { newPool.GetIn(new Swimmer()); } try { newPool.GetIn(johan); // här kastas PoolDirtyException. } catch { Console.WriteLine("All swimmers has to leave the pool!"); newPool.Clean(); } newPool.GetIn(johan); newPool.GetIn(new Swimmer()); // detta borde alltså inte vara något problem längre. Console.WriteLine("----- BubblePoolTest stop \n"); }
public static void SafeBubblePoolTest(String[] args) { Console.WriteLine("----- SafeBubblePoolTest start"); SaveBubblePool newPool = new SaveBubblePool(5, "Den viktig notifikationen"); Swimmer johan = new Swimmer(); for (int i = 4; (i > 0); i--) { newPool.GetIn(new Swimmer()); } newPool.GetIn(johan); newPool.GetIn(new Swimmer()); // detta borde alltså inte vara något problem längre. Console.WriteLine("----- SafeBubblePoolTest stop \n"); }
public override void getOut(Swimmer leaver) { base.getOut(leaver); }
public override void GetIn(Swimmer joiner) { this.GetDirtier(); base.GetIn(joiner); }
public virtual void getOut(Swimmer leaver) { this.people.Remove(leaver); this.GetDirtier(); }
public virtual void GetIn(Swimmer joiner) { this.people.Add(joiner); this.GetDirtier(); }