Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
design_pattern:factory_method_pattern [2017/10/27 12:50] ledyxdesign_pattern:factory_method_pattern [2021/02/07 03:26] (current) – [Factory Method Pattern] ledyx
Line 2: Line 2:
 하위 클래스에서 인스턴스 작성 하위 클래스에서 인스턴스 작성
   * 상위 클래스에서 인스턴스 작성법의 뼈대를 세우고, 구체적인 작성은 하위 클래스에서 실행.   * 상위 클래스에서 인스턴스 작성법의 뼈대를 세우고, 구체적인 작성은 하위 클래스에서 실행.
 +  * [[template_method_pattern]]을 인스턴스 생성에 적용한 패턴.
  
-{{tag>Architecture Modeling DesignPattern Creational}}+{{tag>Architecture Modeling Design_Pattern Creational}}
  
 = 인스턴스 생성을 위한 Framework(골격) 측 = = 인스턴스 생성을 위한 Framework(골격) 측 =
-<sxh java>+<sxh java ; title:Product>
 package framework; package framework;
  
Line 14: Line 15:
 </sxh> </sxh>
  
-<sxh java>+<sxh java ; title:Creator>
 package framework; package framework;
  
 +/* 가장 핵심 부분! */
 public abstract class Factory { public abstract class Factory {
  public final Product create(String owner) {  public final Product create(String owner) {
Line 31: Line 33:
  
 = 구체적인 구현하고 있는 측 = = 구체적인 구현하고 있는 측 =
-<sxh java>+<sxh java ; title:ConcreteProduct>
 package product; package product;
  
Line 54: Line 56:
 </sxh> </sxh>
  
-<sxh java>+<sxh java ; title:ConcreteCreator>
 package product; package product;
  
Line 80: Line 82:
  }  }
 } }
 +</sxh>
 +
 += Client =
 +<sxh java>
 +import framework.*;
 +import product.*;
 +
 +public class Main {
 + public static void main(String[] args) {
 + Factory factory = new IDCardFactory();
 + Product card1 = factory.create("철수");
 + Product card2 = factory.create("영희");
 +
 + card1.use();
 + card2.use();
 + }
 +}
 +
 +/*
 +철수의 카드 사용
 +영희의 카드 사용
 +*/
 </sxh> </sxh>
design_pattern/factory_method_pattern.1509105037.txt.gz · Last modified: 2021/02/07 03:15 (external edit)