You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
2.0 KiB
50 lines
2.0 KiB
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Factory
|
|
{
|
|
/*
|
|
* 카테고리: 생성패턴
|
|
* 개요: 객체를 직접 생성하는 대신 생성하는 기능을 가진 Factory 클래스를 통해 객체를 생성함.
|
|
*
|
|
* static factory method: 정적 메서드가 클래스 또는 서브클래스를 리턴
|
|
*
|
|
* simple factory: 공식적은 디자인 패턴은 아니지만, 객체를 생성하는 과정이 복잡한 경우 new를 사용하여 팩토리 생성 후
|
|
* 클래스 또는 서브클래스를 리턴.
|
|
*
|
|
* factory method: 객체를 생성하는 메서드가 구현 클래스가 아닌 인터페이스 또는 추상클래스에 정의됨.
|
|
* 객체를 생성하는 factory 서브클래스가 여러개일 때 유용.
|
|
*
|
|
* abstract factory: 연관되거나 의존적인 여러 클래스 객체들을 생성하기 위한 인터페이스를 제공함.
|
|
* 여러개의 서로 연관된 객체를 복수 개 생성해야 할 때 유용.
|
|
*/
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
// static factory method
|
|
StaticFactoryMethod.ILogger staticFactoryLogger = StaticFactoryMethod.LoggerFactory.Create(StaticFactoryMethod.LoggerType.DB);
|
|
|
|
// simple factory
|
|
SimpleFactory.LoggerFactory simpleFactory = new SimpleFactory.LoggerFactory();
|
|
SimpleFactory.DbLogger simpleFactoryLogger = simpleFactory.CreateDbLogger();
|
|
|
|
// factory method1
|
|
FactoryMethod.LogFactory factoryLogger1 = new FactoryMethod.XmlLogFactory();
|
|
factoryLogger1.Log("something to be logged");
|
|
|
|
// factory method2
|
|
FactoryMethod.LogFactory factoryLogger2 = FactoryMethod.LogFactory.GetLogger();
|
|
factoryLogger2.Log("something to be logged");
|
|
|
|
// abstract factory method
|
|
AbstractFactory.AbstractFactory abstractFactorty = new AbstractFactory.ConcreteFactory2();
|
|
AbstractFactory.ProductA prodA = abstractFactorty.CreateProductA();
|
|
AbstractFactory.ProductB prodB = abstractFactorty.CreateProductB();
|
|
}
|
|
}
|
|
}
|
|
|