Skip to content

Commit 810b15a

Browse files
committed
add
1 parent 3aa1494 commit 810b15a

31 files changed

+431
-316
lines changed

src/com/duwei/designpattern/singleton/StaticInnerSingleton.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ class StaticInnerSingleton {
44
private StaticInnerSingleton() {}
55

66
private static class HolderClass {
7-
//静态实例属于类,所有HolderClass对象共享一个Singleton实例,
8-
//保证线程安全
7+
//静态实例属于类,所有HolderClass对象共享一个Singleton实例,
8+
//保证线程安全
99
private final static StaticInnerSingleton instance = new StaticInnerSingleton();
1010
}
1111

1212
public static StaticInnerSingleton getInstance() {
1313
return HolderClass.instance;
14-
//初始化类时才初始化外部类对象:懒加载
14+
//初始化类时才初始化外部类对象:懒加载
1515
}
1616
}

src/com/duwei/designpattern/state/Client.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.duwei.designpattern.state;
22
/**
3-
* 状态模式的定义:
4-
* 当一个对象内在状态改变时允许其改变行为
5-
* 状态的改变引起了行为的改变
6-
* @author 杜伟
3+
* 状态模式的定义:
4+
* 当一个对象内在状态改变时允许其改变行为
5+
* 状态的改变引起了行为的改变
6+
* @author 杜伟
77
*
88
*/
99
public class Client {

src/com/duwei/designpattern/state/ClosingState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public void open() {
1010

1111
@Override
1212
public void close() {
13-
System.out.println("µçÌÝÃŹرա£¡£¡£");
13+
System.out.println("电梯门关闭。。。");
1414
}
1515

1616
@Override

src/com/duwei/designpattern/state/Context.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Context {
77
public static final RunningState RUNNING_STATE = new RunningState();
88
public static final StoppingState STOPPING_STATE = new StoppingState();
99

10-
/**ÄÚ²¿×´Ì¬µÄ¿ØÖÆ*/
10+
/**内部状态的控制*/
1111
private LiftState liftState;
1212

1313
public LiftState getLiftState(){

src/com/duwei/designpattern/state/LiftState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.duwei.designpattern.state;
22
/**
3-
* µçÌÝ״̬³éÏóÀà
4-
* @author ¶Åΰ
3+
* 电梯状态抽象类
4+
* @author 杜伟
55
*/
66
public abstract class LiftState {
77
protected Context context;

src/com/duwei/designpattern/state/OpeningState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class OpeningState extends LiftState{
44

55
@Override
66
public void open() {
7-
System.out.println("µçÌÝÃÅ¿ªÁË¡£¡£¡£");
7+
System.out.println("电梯门开了。。。");
88
}
99

1010
@Override

src/com/duwei/designpattern/state/RunningState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void close() {
1212

1313
@Override
1414
public void run() {
15-
System.out.println("µçÌÝÉÏÏÂÔËÐС£¡£¡£");
15+
System.out.println("电梯上下运行。。。");
1616

1717
}
1818

src/com/duwei/designpattern/state/StoppingState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void run() {
2222

2323
@Override
2424
public void stop() {
25-
System.out.println("µçÌÝÍ£Ö¹ÁË¡£¡£¡£");
25+
System.out.println("电梯停止了。。。");
2626
}
2727

2828
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.duwei.designpattern.state2;
2-
//银行账户:环境类
2+
//银行账户:环境类
33
class Account {
4-
private AccountState state; //维持一个对抽象状态对象的引用
5-
private String owner; //开户名
6-
private double balance = 0; //账户余额
4+
private AccountState state; //维持一个对抽象状态对象的引用
5+
private String owner; //开户名
6+
private double balance = 0; //账户余额
77

88
public Account(String owner,double init) {
99
this.owner = owner;
1010
this.balance = balance;
11-
this.state = new NormalState(this); //设置初始状态
12-
System.out.println(this.owner + "开户,初始金额为" + init);
11+
this.state = new NormalState(this); //设置初始状态
12+
System.out.println(this.owner + "开户,初始金额为" + init);
1313
System.out.println("---------------------------------------------");
1414
}
1515

@@ -26,23 +26,23 @@ public void setState(AccountState state) {
2626
}
2727

2828
public void deposit(double amount) {
29-
System.out.println(this.owner + "存款" + amount);
30-
state.deposit(amount); //调用状态对象的deposit()方法
31-
System.out.println("现在余额为"+ this.balance);
32-
System.out.println("现在帐户状态为"+ this.state.getClass().getName());
29+
System.out.println(this.owner + "存款" + amount);
30+
state.deposit(amount); //调用状态对象的deposit()方法
31+
System.out.println("现在余额为"+ this.balance);
32+
System.out.println("现在帐户状态为"+ this.state.getClass().getName());
3333
System.out.println("---------------------------------------------");
3434
}
3535

3636
public void withdraw(double amount) {
37-
System.out.println(this.owner + "取款" + amount);
38-
state.withdraw(amount); //调用状态对象的withdraw()方法
39-
System.out.println("现在余额为"+ this.balance);
40-
System.out.println("现在帐户状态为"+ this. state.getClass().getName());
37+
System.out.println(this.owner + "取款" + amount);
38+
state.withdraw(amount); //调用状态对象的withdraw()方法
39+
System.out.println("现在余额为"+ this.balance);
40+
System.out.println("现在帐户状态为"+ this. state.getClass().getName());
4141
System.out.println("---------------------------------------------");
4242
}
4343

4444
public void computeInterest()
4545
{
46-
state.computeInterest(); //调用状态对象的computeInterest()方法
46+
state.computeInterest(); //调用状态对象的computeInterest()方法
4747
}
4848
}

src/com/duwei/designpattern/state2/AccountState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.duwei.designpattern.state2;
22

3-
//³éÏó״̬Àà
3+
//抽象状态类
44
abstract class AccountState {
55
protected Account acc;
66
public abstract void deposit(double amount);

0 commit comments

Comments
 (0)