/// <summary> /// Registers an egg for a given user. /// </summary> /// <param name="user">The user to register the egg for</param> /// <param name="egg">The egg to register for the user</param> /// <returns>Whether the egg was registered to the user</returns> public static bool RegisterEggFor([NotNull] string user, [NotNull] IEasterEgg egg) { if (!Eggs.ContainsKey(user.ToLowerInvariant())) { Eggs.Add(user.ToLowerInvariant(), egg); return(true); } return(false); }
public static void Main() { // Create a new Dark Chocolate Factory. IChocolateFactory factory = new DarkChocolateFactory(); // Use the factory to create a bar. IChocolateBar chocolate = factory.CreateBar(); // Print flavour and description of bar. Console.WriteLine(chocolate.GetFlavour()); Console.WriteLine(chocolate.GetDescription()); factory = new WhiteChocolateFactory(); IEasterEgg easterEgg = factory.CreateEasterEgg(); Console.WriteLine(easterEgg.GetFlavour()); Console.WriteLine(easterEgg.GetDescription()); }
public static bool TryGetEggFor([NotNull] string user, out IEasterEgg egg) { egg = GetEggFor(user); return(egg != null); }