Skip to content

Commit dbbaa9e

Browse files
author
hp
committed
[edit]builder模式代码纠正错字,优化命名和排版
1 parent 04f4d1e commit dbbaa9e

4 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/com/anxpp/designpattern/builder/DateBuilder1.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.anxpp.designpattern.builder;
22

3-
//具体生成器
3+
// 具体生成器
44
public class DateBuilder1 implements IDateBuilder {
5-
private MyDate myDate;
5+
private final MyDate myDate;
66

77
public DateBuilder1(MyDate myDate) {
88
this.myDate = myDate;
99
}
1010

1111
@Override
12-
public IDateBuilder buildDate(int y, int m, int d) {
13-
myDate.date = y + "-" + m + "-" + d;
12+
public IDateBuilder buildDate(int year, int month, int day) {
13+
myDate.date = year + "-" + month + "-" + day;
1414
return this;
1515
}
1616

src/com/anxpp/designpattern/builder/DateBuilder2.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
//具体生成器
44
public class DateBuilder2 implements IDateBuilder {
5-
private MyDate myDate;
5+
private final MyDate myDate;
66

77
public DateBuilder2(MyDate myDate) {
88
this.myDate = myDate;
99
}
1010

1111
@Override
12-
public IDateBuilder buildDate(int y, int m, int d) {
13-
myDate.date = y + " " + m + " " + d;
12+
public IDateBuilder buildDate(int year, int month, int day) {
13+
myDate.date = year + " " + month + " " + day;
1414
return this;
1515
}
1616

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package com.anxpp.designpattern.builder;
2-
3-
//指挥者
4-
public class Derector {
5-
private IDateBuilder builder;
6-
7-
public Derector(IDateBuilder builder) {
8-
this.builder = builder;
9-
}
10-
11-
public String getDate(int y, int m, int d) {
12-
builder.buildDate(y, m, d);
13-
return builder.date();
14-
}
15-
}
1+
package com.anxpp.designpattern.builder;
2+
3+
//指挥者
4+
public class Director {
5+
private final IDateBuilder builder;
6+
7+
public Director(IDateBuilder builder) {
8+
this.builder = builder;
9+
}
10+
11+
public String getDate(int y, int m, int d) {
12+
builder.buildDate(y, m, d);
13+
return builder.date();
14+
}
15+
}

src/com/anxpp/designpattern/builder/TestUse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.anxpp.designpattern.builder;
22

33
public class TestUse {
4-
public static void main(String args[]) {
4+
public static void main(String[] args) {
55
MyDate date = new MyDate();
66
IDateBuilder builder;
77
builder = new DateBuilder1(date).buildDate(2066, 3, 5);

0 commit comments

Comments
 (0)