略读设计模式(三)

外观模式:

class SubSystemA {
    public void MethodA() {
    }
}
class SubSystemB {
    public void MethodB() {
    }
}
class SubSystemC {
    public void MethodC() {
    }
}
class Facade {
    private SubSystemA  obj1    =   new SubSystemA();
    private SubSystemB  obj2    =   new SubSystemB();
    private SubSystemC  obj3    =   new SubSystemC();
    public void Method() {
        obj1.MethodA();
        obj2.MethodB();
        obj3.MethodC();
    }
}

代理模式:

abstract class Subject {
    public abstract void Request();
}

class RealSubject extends Subject {
    public void Request() {
    }
}

class Proxy extends Subject {
    private RealSubject realSubject = new RealSubject();
    public void PreRequest() {
    }
    public void Request() {
        PreRequest();
        realSubject.Request();
        PostRequest();
    }
    public void PostRequest() {
    }
}

职责链模式:

abstract class Handler {
    protected Handler successor;
    public void etSuccessor(Handler successor) {
        this.successor=successor;
    }
    public abstract void handleRequest(String request);
}

class ConcreteHandler extends Handler {
    public void handleRequest(String request) {
        if (请求满足条件) {
        } else {
            this.successor.handleRequest(request);
        }
    }
}

书籍连接地址:https://gof.quanke.name/

0

一个有关“略读设计模式(三)”的想法

发表评论