https://refactoring.guru/design-patterns/builder
특정 단계가 필요한 절차대로 생성되는 어떤 대상들에 대해 각 상황에 걸맞는 생성코드 제작.
어떤 특정 제작단계가 반드시 정의되어야 한다.
예시
Pizza Builder
Coffee Builder
House Builder
Dialog Builder
예제 코드
더보기
public interface IDialogBuilder
{
void BuildTitle();
void BuildContent();
void BuildButtons();
}
public class Dialog
{
}
public abstract class ADialogBuilder : IDialogBuilder
{
protected Dialog _dlgBase = null;
public virtual void Init() { _dlgBase = new Dialog(); }
public abstract void BuildTitle();
public abstract void BuildContent();
public abstract void BuildButtons();
}
public class MessageDialogBuilder : ADialogBuilder
{
public override void BuildTitle() {}
public override void BuildContent() {}
public override void BuildButtons() {}
}
public class WarningDialogBuilder : ADialogBuilder
{
public override void BuildTitle() {}
public override void BuildContent() {}
public override void BuildButtons() {}
}
public class BuilderDemo
{
public void Main()
{
ADialogBuilder dialog = new MessageDialogBuilder();
dialog.Init();
dialog.BuildTitle();
dialog.BuildContent();
dialog.BuildButtons();
}
}
'Work & Programming > System Design' 카테고리의 다른 글
[Structural Pattern] - Adapter (0) | 2024.05.15 |
---|---|
[Creational Pattern] - Singleton (0) | 2024.05.15 |
[Creational Pattern] - Abstract Factory (0) | 2024.05.15 |
[Structural Patterns] 특징과 사용례. (0) | 2024.04.07 |
[Creational Patterns] 특징과 사용례. (0) | 2024.04.07 |