Skip to content

Commit 1e83657

Browse files
committed
#commit 2021_02_15_16_12
1 parent f819639 commit 1e83657

File tree

2 files changed

+132
-128
lines changed

2 files changed

+132
-128
lines changed

res/doc/pattern/cp/prototype/prototype.md

+1-128
Original file line numberDiff line numberDiff line change
@@ -158,132 +158,5 @@ public class Client {
158158
159159
###### [代码](../../../../../src/main/java/org/fade/pattern/cp/prototype/improve)
160160

161-
#### 在Spring中的源码分析
162-
163-
###### [代码](../../../../../src/main/java/org/fade/pattern/cp/prototype/spring)
164-
165-
```xml
166-
<?xml version="1.0" encoding="UTF-8" ?>
167-
<beans xmlns="http://www.springframework.org/schema/beans"
168-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
169-
xsi:schemaLocation="http://www.springframework.org/schema/beans
170-
http://www.springframework.org/schema/beans/spring-beans.xsd">
171-
172-
<bean id="id01" class="org.fade.pattern.cp.prototype.spring.Monster" scope="prototype" />
173-
174-
</beans>
175-
```
176-
177-
```java
178-
public class Monster {
179-
180-
private Integer id = 10;
181-
182-
private String nickName = "牛魔王";
183-
184-
private String skill = "芭蕉扇";
185-
186-
public Monster(){
187-
188-
}
189-
190-
public Monster(Integer id, String nickName, String skill) {
191-
this.id = id;
192-
this.nickName = nickName;
193-
this.skill = skill;
194-
}
195-
196-
public Integer getId() {
197-
return id;
198-
}
199-
200-
public void setId(Integer id) {
201-
this.id = id;
202-
}
203-
204-
public String getNickName() {
205-
return nickName;
206-
}
207-
208-
public void setNickName(String nickName) {
209-
this.nickName = nickName;
210-
}
211-
212-
public String getSkill() {
213-
return skill;
214-
}
215-
216-
public void setSkill(String skill) {
217-
this.skill = skill;
218-
}
219-
220-
@Override
221-
public String toString() {
222-
return "Monster{" +
223-
"id=" + id +
224-
", nickName='" + nickName + '\'' +
225-
", skill='" + skill + '\'' +
226-
'}';
227-
}
228-
229-
}
230-
231-
public class Prototype {
232-
233-
public static void main(String[] args) {
234-
ApplicationContext applicationContext = new FileSystemXmlApplicationContext(System.getProperty("user.dir")
235-
+"/src/main/java/org/fade/pattern/cp/prototype/spring/ApplicationContext.xml");
236-
Object bean1 = applicationContext.getBean("id01");
237-
System.out.println("bean1:"+bean1);
238-
Object bean2 = applicationContext.getBean("id01");
239-
System.out.println("bean2:"+bean2);
240-
System.out.println(bean1==bean2);
241-
}
242-
243-
}
244-
```
245-
246-
###### 运行结果
247-
248-
```
249-
bean1:Monster{id=10, nickName='牛魔王', skill='芭蕉扇'}
250-
bean2:Monster{id=10, nickName='牛魔王', skill='芭蕉扇'}
251-
false
252-
```
253-
254-
###### DEBUG调试
255-
256-
1. ###### 单击图示处打上断点
257-
258-
![#1](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-39-02.png)
259-
260-
2. ###### 右键点击图示1处,选择图示2处选项“Debug 'Prototype.main()'”
261-
262-
![#2](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-41-59.png)
263-
264-
3. ###### 等调试系统上线后,点击图示处选项“Step Into”
265-
266-
![#3](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-45-52.png)
267-
268-
4. ###### 再点击图示处选项“Step Over”
269-
270-
![#4](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-47-16.png)
271-
272-
5. ###### 当代码运行至下图所示时,再次点击选项“Step Into”
273-
274-
![#5](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-49-03.png)
275-
276-
6. ###### 当出现如下图所示内容时,点击“getBean”
277-
278-
![#6](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-51-26.png)
279-
280-
7. ###### 当出现如下图所示内容时,点击选项“Step Into”
281-
282-
![#7](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-54-33.png)
283-
284-
285-
8. ###### 滚动页面,当代码为下图所示的内容时,可以发现此处Spring中确实采用了原型模式
286-
287-
![#8](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-56-21.png)
288-
161+
#### [在Spring中的源码分析](spring.md)
289162

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# 在Spring中的源码分析
2+
3+
#### 例子
4+
5+
```xml
6+
<?xml version="1.0" encoding="UTF-8" ?>
7+
<beans xmlns="http://www.springframework.org/schema/beans"
8+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:schemaLocation="http://www.springframework.org/schema/beans
10+
http://www.springframework.org/schema/beans/spring-beans.xsd">
11+
12+
<bean id="id01" class="org.fade.pattern.cp.prototype.spring.Monster" scope="prototype" />
13+
14+
</beans>
15+
```
16+
17+
```java
18+
public class Monster {
19+
20+
private Integer id = 10;
21+
22+
private String nickName = "牛魔王";
23+
24+
private String skill = "芭蕉扇";
25+
26+
public Monster(){
27+
28+
}
29+
30+
public Monster(Integer id, String nickName, String skill) {
31+
this.id = id;
32+
this.nickName = nickName;
33+
this.skill = skill;
34+
}
35+
36+
public Integer getId() {
37+
return id;
38+
}
39+
40+
public void setId(Integer id) {
41+
this.id = id;
42+
}
43+
44+
public String getNickName() {
45+
return nickName;
46+
}
47+
48+
public void setNickName(String nickName) {
49+
this.nickName = nickName;
50+
}
51+
52+
public String getSkill() {
53+
return skill;
54+
}
55+
56+
public void setSkill(String skill) {
57+
this.skill = skill;
58+
}
59+
60+
@Override
61+
public String toString() {
62+
return "Monster{" +
63+
"id=" + id +
64+
", nickName='" + nickName + '\'' +
65+
", skill='" + skill + '\'' +
66+
'}';
67+
}
68+
69+
}
70+
71+
public class Prototype {
72+
73+
public static void main(String[] args) {
74+
ApplicationContext applicationContext = new FileSystemXmlApplicationContext(System.getProperty("user.dir")
75+
+"/src/main/java/org/fade/pattern/cp/prototype/spring/ApplicationContext.xml");
76+
Object bean1 = applicationContext.getBean("id01");
77+
System.out.println("bean1:"+bean1);
78+
Object bean2 = applicationContext.getBean("id01");
79+
System.out.println("bean2:"+bean2);
80+
System.out.println(bean1==bean2);
81+
}
82+
83+
}
84+
```
85+
86+
#### 运行结果
87+
88+
```
89+
bean1:Monster{id=10, nickName='牛魔王', skill='芭蕉扇'}
90+
bean2:Monster{id=10, nickName='牛魔王', skill='芭蕉扇'}
91+
false
92+
```
93+
94+
#### [代码](../../../../../src/main/java/org/fade/pattern/cp/prototype/spring)
95+
96+
#### DEBUG调试
97+
98+
1. ###### 单击图示处打上断点
99+
100+
![#1](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-39-02.png)
101+
102+
2. ###### 右键点击图示1处,选择图示2处选项“Debug 'Prototype.main()'”
103+
104+
![#2](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-41-59.png)
105+
106+
3. ###### 等调试系统上线后,点击图示处选项“Step Into”
107+
108+
![#3](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-45-52.png)
109+
110+
4. ###### 再点击图示处选项“Step Over”
111+
112+
![#4](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-47-16.png)
113+
114+
5. ###### 当代码运行至下图所示时,再次点击选项“Step Into”
115+
116+
![#5](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-49-03.png)
117+
118+
6. ###### 当出现如下图所示内容时,点击“getBean”
119+
120+
![#6](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-51-26.png)
121+
122+
7. ###### 当出现如下图所示内容时,点击选项“Step Into”
123+
124+
![#7](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-54-33.png)
125+
126+
127+
8. ###### 滚动页面,当代码为下图所示的内容时,可以发现此处Spring中确实采用了原型模式
128+
129+
![#8](../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-56-21.png)
130+
131+

0 commit comments

Comments
 (0)