static void Main(string[] args) { Console.WriteLine("Please select a design pattern:"); foreach (var item in Enum.GetValues(typeof(DesignPatternType))) { Console.WriteLine((int)item + ": " + item.ToString()); } Console.Write("You select number :"); var number = int.Parse(Console.ReadLine()); switch (number) { case (int)DesignPatternType.Factory: FactoryProgram.Work(); break; case (int)DesignPatternType.Builder: BuilderProgram.Work(); break; case (int)DesignPatternType.Prototype: PrototypeProgram.Work(); break; case (int)DesignPatternType.Singleton: SingletonProgram.Work(); break; case (int)DesignPatternType.Bridge: BridgeProgram.Work(); break; case (int)DesignPatternType.Proxy: ProxyProgram.Work(); break; case (int)DesignPatternType.Strategy: StrategyProgram.Work(); break; default: Console.Write("Not support!"); break; } }
public static void SDPatternRun() { try { bool flag = true; int choice; while (flag) { Console.WriteLine("\n\t------------Structural Design Patterns------------\n"); Console.WriteLine("\t\t1. Adapter Design Pattern"); Console.WriteLine("\t\t2. Facade Design Pattern"); Console.WriteLine("\t\t3. Proxy Design Pattern"); Console.WriteLine("\t\t4. Exit"); Console.Write("\tEnter your choice: "); choice = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(); switch (choice) { case 1: AdapterProgram.AdapterRun(); break;; case 2: AddressBookProgram.AddressBookRun(); break; case 3: ProxyProgram.ProxyRun(); break; case 4: flag = false; break; default: Console.WriteLine("Invalid choice!"); break; } } } catch (Exception ex) { Console.WriteLine("Message: {0}", ex.Message); } }