본문 바로가기

C# Creational Patterns6

07# Singleton 패턴(thread safe) Creational Patterns static void Main(string[] args) { //BuilderExample(); //FactoryExample(); //FactoryMethodExample(); //FactoryMethodExample2(); //ProtoTypeExample(); SingletonExample(); //Console.WriteLine("Hello World!"); Console.ReadKey(); } static void SingletonExample() { LazySingleton.IsValueCreated(); Console.WriteLine("Name : {0} Age : {1}", LazySingleton.Instance.Name, LazySingleton.Instance.Age); LazySi.. 2019. 5. 24.
06# Prototype 패턴 Creational Patterns static void Main(string[] args) { //BuilderExample(); //FactoryExample(); //FactoryMethodExample(); //FactoryMethodExample2(); ProtoTypeExample(); //Console.WriteLine("Hello World!"); Console.ReadKey(); } static void ProtoTypeExample() { ColorManager colorManager = new ColorManager(); colorManager["red"] = new Color(255, 0, 0); colorManager["green"] = new Color(0, 255, 0); colorManager["blue"] =.. 2019. 5. 23.
05# Factory Method 패턴2 Creational Patterns static void Main(string[] args) { //BuilderExample(); //FactoryExample(); //FactoryMethodExample(); FactoryMethodExample2(); //Console.WriteLine("Hello World!"); Console.ReadKey(); } static void FactoryMethodExample2() { LogManager logManager = new LogManager(); logManager.AddLog(typeof(Human).Name, new Human()); logManager.AddLog(typeof(Animal).Name, new Animal()); foreach (string key in logMan.. 2019. 5. 23.
04# Factory Method 패턴1 Creational Patterns static void Main(string[] args) { //BuilderExample(); //FactoryExample(); FactoryMethodExample(); //Console.WriteLine("Hello World!"); Console.ReadKey(); } static void FactoryMethodExample() { Document[] documents = new Document[2]; documents[0] = new Resume(); documents[1] = new Report(); foreach(Document document in documents) { Console.WriteLine(string.Format("{0}--", document.GetType().Name).. 2019. 5. 23.