private static void Main(string[] args) { //Can't do this as wont compile //WickedRoom room = new WickedRoom(); //have to use the factory method: WickedRoom room1 = WickedRoom.GetWickedRoom(); WickedRoom room2 = WickedRoom.GetWickedRoom(); //actually the same room Debug.Assert(room1 == room2); }
public static WickedRoom GetWickedRoom() { WickedRoom result = GetAlreadyCreatedRoom <WickedRoom>(); if (result == null) { //create a room, and store result = new WickedRoom(); createdRooms.Add(result); } return(result); }
private static void Main(string[] args) { //Can't do this as wont compile //WickedRoom room = new WickedRoom(); //have to use the factory method: WickedRoom room1 = WickedRoom.GetWickedRoom(); WickedRoom room2 = WickedRoom.GetWickedRoom(); //actually the same room Debug.Assert(room1 == room2); NaughtyRoom room3 = new NaughtyRoom(); //Allowed, just this once! NaughtyRoom room4 = new NaughtyRoom(); //exception, can't create another }