Skip to content

Commit 5ae15d1

Browse files
committed
设计模式-建造者模式
1 parent e134ec2 commit 5ae15d1

File tree

4 files changed

+247
-0
lines changed

4 files changed

+247
-0
lines changed

DesignPattern/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
</exclusion>
3636
</exclusions>
3737
</dependency>
38+
39+
<dependency>
40+
<groupId>org.projectlombok</groupId>
41+
<artifactId>lombok</artifactId>
42+
</dependency>
3843
</dependencies>
3944

4045
<build>
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package com.design.builder;
2+
3+
import java.util.Date;
4+
5+
/**
6+
* 应用
7+
*
8+
* @author wliduo[i@dolyw.com]
9+
* @date 2022/2/11 14:13
10+
*/
11+
public class App {
12+
13+
/** 主键ID */
14+
private Long appId;
15+
16+
/** 应用代码 */
17+
private String appCode;
18+
19+
/** 应用名称 */
20+
private String appName;
21+
22+
/** 应用私钥 */
23+
private String appSecret;
24+
25+
/** 应用类型 */
26+
private String appType;
27+
28+
/** 创建人 */
29+
private String createdBy;
30+
31+
/** 创建时间 */
32+
private Date createdTime;
33+
34+
public Long getAppId() {
35+
return appId;
36+
}
37+
38+
public void setAppId(Long appId) {
39+
this.appId = appId;
40+
}
41+
42+
public String getAppCode() {
43+
return appCode;
44+
}
45+
46+
public void setAppCode(String appCode) {
47+
this.appCode = appCode;
48+
}
49+
50+
public String getAppName() {
51+
return appName;
52+
}
53+
54+
public void setAppName(String appName) {
55+
this.appName = appName;
56+
}
57+
58+
public String getAppSecret() {
59+
return appSecret;
60+
}
61+
62+
public void setAppSecret(String appSecret) {
63+
this.appSecret = appSecret;
64+
}
65+
66+
public String getAppType() {
67+
return appType;
68+
}
69+
70+
public void setAppType(String appType) {
71+
this.appType = appType;
72+
}
73+
74+
public String getCreatedBy() {
75+
return createdBy;
76+
}
77+
78+
public void setCreatedBy(String createdBy) {
79+
this.createdBy = createdBy;
80+
}
81+
82+
public Date getCreatedTime() {
83+
return createdTime;
84+
}
85+
86+
public void setCreatedTime(Date createdTime) {
87+
this.createdTime = createdTime;
88+
}
89+
90+
/**
91+
* 建造者模式
92+
*
93+
* @return
94+
*/
95+
public static Builder Builder() {
96+
return new Builder();
97+
}
98+
99+
/**
100+
* 建造者模式 - Builder内部类
101+
*/
102+
public static final class Builder {
103+
private Long appId;
104+
private String appCode;
105+
private String appName;
106+
private String appSecret;
107+
private String appType;
108+
private String createdBy;
109+
private Date createdTime;
110+
111+
private Builder() {
112+
}
113+
114+
public Builder withAppId(Long appId) {
115+
this.appId = appId;
116+
return this;
117+
}
118+
119+
public Builder withAppCode(String appCode) {
120+
this.appCode = appCode;
121+
return this;
122+
}
123+
124+
public Builder withAppName(String appName) {
125+
this.appName = appName;
126+
return this;
127+
}
128+
129+
public Builder withAppSecret(String appSecret) {
130+
this.appSecret = appSecret;
131+
return this;
132+
}
133+
134+
public Builder withAppType(String appType) {
135+
this.appType = appType;
136+
return this;
137+
}
138+
139+
public Builder withCreatedBy(String createdBy) {
140+
this.createdBy = createdBy;
141+
return this;
142+
}
143+
144+
public Builder withCreatedTime(Date createdTime) {
145+
this.createdTime = createdTime;
146+
return this;
147+
}
148+
149+
public App build() {
150+
App app = new App();
151+
app.setAppId(appId);
152+
app.setAppCode(appCode);
153+
app.setAppName(appName);
154+
app.setAppSecret(appSecret);
155+
app.setAppType(appType);
156+
app.setCreatedBy(createdBy);
157+
app.setCreatedTime(createdTime);
158+
return app;
159+
}
160+
}
161+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.design.builder;
2+
3+
import lombok.Builder;
4+
import lombok.Data;
5+
6+
import java.util.Date;
7+
8+
/**
9+
* 渠道
10+
*
11+
* @author wliduo[i@dolyw.com]
12+
* @date 2022/2/11 14:13
13+
*/
14+
@Data
15+
@Builder
16+
public class Channel {
17+
18+
/** 主键ID */
19+
private Long channelId;
20+
21+
/** 渠道代码 */
22+
private String channelCode;
23+
24+
/** 渠道名称 */
25+
private String channelName;
26+
27+
/** 渠道类型 */
28+
private Integer channelType;
29+
30+
/** 渠道状态:1-待审核 2-审核通过 3-合作中 4-暂停合作 5-废弃 */
31+
private Integer status;
32+
33+
/** 渠道生效日期 */
34+
private Date effectiveDate;
35+
36+
/** 渠道失效日期 */
37+
private Date invalidDate;
38+
39+
/** 渠道联系人 */
40+
private String channelContactName;
41+
42+
/** 渠道联系电话 */
43+
private String channelContactPhone;
44+
45+
/** 渠道联系邮箱 */
46+
private String channelContactEmail;
47+
48+
/** 创建人 */
49+
private String createdBy;
50+
51+
/** 创建时间 */
52+
private Date createdTime;
53+
54+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.design.builder;
2+
3+
import java.util.Date;
4+
5+
/**
6+
* 建造者模式
7+
*
8+
* @author wliduo[i@dolyw.com]
9+
* @date 2022/2/11 14:27
10+
*/
11+
public class Main {
12+
13+
public static void main(String[] args) {
14+
App app = App.Builder()
15+
.withAppId(1L)
16+
.withAppCode("App")
17+
.withAppName("XX系统")
18+
.withCreatedBy("XXX")
19+
.build();
20+
Channel channel = Channel.builder()
21+
.channelId(1L)
22+
.channelName("XXX")
23+
.channelType(1)
24+
.createdTime(new Date())
25+
.build();
26+
}
27+
}

0 commit comments

Comments
 (0)