private static void SingletonExample() { Highlander john = Highlander.GetInstance(); Highlander rick = Highlander.GetInstance(); Console.WriteLine($"john is equal to rick? {ReferenceEquals(john, rick)}"); }
public void ArmoredSwordsmanVsHighlander() { Highlander highlander = new Highlander(); Swordsman swordsman = new Swordsman() .Equip("buckler") .Equip("armor"); swordsman.Engage(highlander); Assert.AreEqual(0, swordsman.HitPoints()); Assert.AreEqual(10, highlander.HitPoints()); }
public void ViciousSwordsmanVsVeteranHighlander() { Swordsman swordsman = new Swordsman("Vicious") .Equip("axe") .Equip("buckler") .Equip("armor"); Highlander highlander = new Highlander("Veteran"); swordsman.Engage(highlander); Assert.AreEqual(1, swordsman.HitPoints()); Assert.AreEqual(0, highlander.HitPoints()); }
public static Highlander GetInstance() { return(_highlander ?? (_highlander = new Highlander())); }