Update 设计模式.md

枚举代码风格修正
This commit is contained in:
Elong 2018-09-07 11:07:21 +08:00 committed by GitHub
parent 187f0bd023
commit 24c4864bfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -657,7 +657,7 @@ public class ConcreteHandler1 extends Handler {
@Override
protected void handleRequest(Request request) {
if (request.getType() == RequestType.type1) {
if (request.getType() == RequestType.TYPE1) {
System.out.println(request.getName() + " is handle by ConcreteHandler1");
return;
}
@ -676,7 +676,7 @@ public class ConcreteHandler2 extends Handler{
@Override
protected void handleRequest(Request request) {
if (request.getType() == RequestType.type2) {
if (request.getType() == RequestType.TYPE2) {
System.out.println(request.getName() + " is handle by ConcreteHandler2");
return;
}
@ -709,7 +709,7 @@ public class Request {
```java
public enum RequestType {
type1, type2
TYPE1, TYPE2
}
```
@ -718,9 +718,9 @@ public class Client {
public static void main(String[] args) {
Handler handler1 = new ConcreteHandler1(null);
Handler handler2 = new ConcreteHandler2(handler1);
Request request1 = new Request(RequestType.type1, "request1");
Request request1 = new Request(RequestType.TYPE1, "request1");
handler2.handleRequest(request1);
Request request2 = new Request(RequestType.type2, "request2");
Request request2 = new Request(RequestType.TYPE2, "request2");
handler2.handleRequest(request2);
}
}