Skip to content

Commit e5f89a6

Browse files
author
aronerry
committed
modify
1 parent 4ae6a90 commit e5f89a6

File tree

17 files changed

+205
-49
lines changed

17 files changed

+205
-49
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
6+
<classpathentry kind="output" path="bin/classes"/>
7+
</classpath>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>JAA_Chapter9.4.1</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
《Java应用架构设计》源代码示例
2+
3+
[Chapter 9][Section 4][Code 1] - 容器独立 - 原始版本
4+
-
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
6+
<classpathentry kind="output" path="bin/classes"/>
7+
</classpath>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>JAA_Chapter9.4.2</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
《Java应用架构设计》源代码示例
2+
3+
[Chapter 9][Section 4][Code 2] - 容器独立 - 独立版本
4+
- 将HelloConsumer与HelloServiceImpl中对OSGi的依赖转移到Spring中xml配置文件中
5+
6+
7+
springconfig.xml
8+
--------- |
9+
---------- |
10+
------------------^----------------------|--------------------------------------
11+
class - HelloConsumer | module - client.jar
12+
-----------------------------------------|----------------------------|---------
13+
| | |
14+
| | |
15+
| | |
16+
| | |
17+
| | |
18+
-----------^-----------------------------^----------------------------^---------
19+
impl - HelloService <---- class - HelloServerImpl module - service.jar
20+
--------------------------------------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
6+
<classpathentry kind="lib" path="lib/jaranalyzer-1.2.jar"/>
7+
<classpathentry kind="output" path="bin/classes"/>
8+
</classpath>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>JAA_Chapter9.5.1</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
《Java应用架构设计》源代码示例
2+
3+
[Chapter 9][Section 5][Code 1] - 独立部署 - 原始版本
4+
-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/classes/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
6+
<classpathentry kind="output" path="bin/classes"/>
7+
</classpath>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>JAA_Chapter9.5.2</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
《Java应用架构设计》源代码示例
2+
3+
[Chapter 9][Section 5][Code 2] - 独立部署 - 独立版本
4+
- 修改了Employee中的pay()方法,移除了对Payroll的依赖
5+
- 新增PayrollRunner接口,通过实现类去调用Payroll进行具体计算
6+
- 新的Employee中pay()与PayrollRunner关联
7+
- 打破employee.jar对payroll.jar的依赖
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/classes/
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
package com.extensiblejava.employee;
2-
3-
import java.math.BigDecimal;
4-
5-
public class PayCheck {
6-
private BigDecimal pay;
7-
public PayCheck(BigDecimal pay) {
8-
this.pay = pay;
9-
}
10-
11-
public BigDecimal getPay() { return this.pay; }
1+
package com.extensiblejava.employee;
2+
3+
import java.math.BigDecimal;
4+
5+
/**
6+
* 相较于上一版本无变化
7+
*
8+
*/
9+
public class PayCheck {
10+
private BigDecimal pay;
11+
public PayCheck(BigDecimal pay) {
12+
this.pay = pay;
13+
}
14+
15+
public BigDecimal getPay() { return this.pay; }
1216
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
package com.extensiblejava.payroll;
2-
3-
import java.math.BigDecimal;
4-
5-
public class Payroll {
6-
7-
private BigDecimal salary;
8-
public Payroll(BigDecimal salary) {
9-
this.salary = salary;
10-
}
11-
12-
public BigDecimal run() {
13-
//calculate the pay...
14-
return new BigDecimal("20000.00");
15-
}
1+
package com.extensiblejava.payroll;
2+
3+
import java.math.BigDecimal;
4+
5+
/**
6+
* 相较于上一版本无变化
7+
*
8+
*/
9+
public class Payroll {
10+
11+
private BigDecimal salary;
12+
public Payroll(BigDecimal salary) {
13+
this.salary = salary;
14+
}
15+
16+
public BigDecimal run() {
17+
//calculate the pay...
18+
return new BigDecimal("20000.00");
19+
}
1620
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1-
package com.extensiblejava.test;
2-
3-
import junit.framework.TestCase;
4-
import com.extensiblejava.employee.*;
5-
import java.math.BigDecimal;
6-
7-
public class EmployeeTest extends TestCase {
8-
9-
public static void main(String[] args) {
10-
junit.textui.TestRunner.run(EmployeeTest.class);
11-
}
12-
13-
public void testEmployeePay() {
14-
15-
PayrollRunner runner = new PayrollRunner() {
16-
public BigDecimal runPayroll(BigDecimal salary) { return new BigDecimal("500.00"); }
17-
};
18-
Employee employee = new Employee(new Name(), new BigDecimal("20000.00"));
19-
PayCheck payCheck = employee.pay(runner);
20-
assertEquals(payCheck.getPay(), new BigDecimal("500.00"));
21-
22-
}
23-
}
1+
package com.extensiblejava.test;
2+
3+
import java.math.BigDecimal;
4+
5+
import junit.framework.TestCase;
6+
7+
import com.extensiblejava.employee.Employee;
8+
import com.extensiblejava.employee.Name;
9+
import com.extensiblejava.employee.PayCheck;
10+
import com.extensiblejava.employee.PayrollRunner;
11+
import com.extensiblejava.facade.PayFacade;
12+
13+
public class EmployeeTest extends TestCase {
14+
15+
public static void main(String[] args) {
16+
junit.textui.TestRunner.run(EmployeeTest.class);
17+
}
18+
19+
public void testEmployeePayWithoutPayFacade() {
20+
21+
PayrollRunner runner = new PayrollRunner() {
22+
public BigDecimal runPayroll(BigDecimal salary) { return new BigDecimal("500.00"); }
23+
};
24+
Employee employee = new Employee(new Name(), new BigDecimal("20000.00"));
25+
PayCheck payCheck = employee.pay(runner);
26+
assertEquals(payCheck.getPay(), new BigDecimal("500.00"));
27+
28+
}
29+
30+
public void testEmployeePay() {
31+
PayFacade runner = new PayFacade();
32+
Employee employee = new Employee(new Name(), new BigDecimal("20000.00"));
33+
PayCheck payCheck = employee.pay(runner);
34+
assertEquals(payCheck.getPay(), new BigDecimal("20000.00"));
35+
}
36+
}

0 commit comments

Comments
 (0)