1//////////////////////////////////// PhoneBuilder.java
2public interface PhoneBuilder {
3
4
5 void buildName();
6 void buildRealeseDate();
7 void buildCompanyName();
8 void buildIsAndroid();
9 void buildIsKoreaCompany();
10 Phone getPhone();
11
12}
13
14//////////////////////////////////// Iphone13Builder.java
15public class Iphone13Builder implements PhoneBuilder{
16
17 private Phone phone;
18
19 public Iphone13Builder() {
20 this.phone = new Phone();
21 }
22
23 @Override
24 public void buildName() {
25 phone.setName("Iphone13");
26 }
27
28 @Override
29 public void buildRealeseDate() {
30 phone.setCompanyName("202110");
31 }
32
33 @Override
34 public void buildCompanyName() {
35 phone.setCompanyName("apple");
36 }
37
38 @Override
39 public void buildIsAndroid() {
40 phone.setIsAndroid(false);
41 }
42
43 @Override
44 public void buildIsKoreaCompany() {
45 phone.setIsKoreaCompany(false);
46 }
47
48 @Override
49 public Phone getPhone() {
50 return this.phone;
51 }
52}
53
54//////////////////////////////////// Phone.java
55public class Phone{
56
57 private String name;
58 private String realeseDate;
59 private String companyName;
60 private boolean isAndroid;
61 private boolean isKoreaCompany;
62
63 // setter와 getter를 만든다
64 public void setName(String name) {
65 this.name = name;
66 }
67
68 public void setRealeseDate(String realeseDate) {
69 this.realeseDate = realeseDate;
70 }
71
72
73 public void setCompanyName(String companyName) {
74 this.companyName = companyName;
75 }
76
77
78 public void setIsAndroid(boolean isAndroid) {
79 this.isAndroid = isAndroid;
80 }
81
82
83 public void setIsKoreaCompany(boolean isKoreaCompany) {
84 this.isKoreaCompany = isKoreaCompany;
85 }
86
87
88 public String getName() {
89 return name;
90 }
91
92 public String getRealeseDate() {
93 return realeseDate;
94 }
95
96 public String getCompanyName() {
97 return companyName;
98 }
99
100 public boolean isAndroid() {
101 return isAndroid;
102 }
103
104 public boolean isKoreaCompany() {
105 return isKoreaCompany;
106 }
107}
108
109//////////////////////////////////// Director.java
110
111public class Director {
112
113 private PhoneBuilder phoneBuilder;
114
115 public Director(PhoneBuilder phoneBuilder) {
116 this.phoneBuilder = phoneBuilder;
117 }
118
119 public Phone getPhone(){
120 return this.phoneBuilder.getPhone();
121 }
122
123 public void makePhone(){
124 this.phoneBuilder.buildName();
125 this.phoneBuilder.buildCompanyName();
126 this.phoneBuilder.buildRealeseDate();
127 this.phoneBuilder.buildIsAndroid();
128 this.phoneBuilder.buildIsKoreaCompany();
129
130 }
131
132}
133
134
135//////////////////////////////////// Main.java
136
137public class Main {
138
139 public static void main(String[] args){
140
141 PhoneBuilder iphoneBuilder = new Iphone13Builder(); // 아이폰13 빌더
142 Director director = new Director(iphoneBuilder); // 지시자에게 주입
143 director.makePhone(); // 지시
144 Phone madePhone = director.getPhone(); // 완성품
145
146 System.out.println("madePhone.getName() = " + madePhone.getName());
147 System.out.println("madePhone.getCompanyName() = " + madePhone.getCompanyName());
148 }
149}