设计模式——窗口模式

284 阅读1分钟

最新修改已更新到github

窗口模式_隐藏系统内部复杂性(安全性),从而提供一个统一的对外调用窗口

/**
 * 用户信息门面
 * @author maikec
 * @date 2019/5/14
 */
public class UserInfoFacade {
    public byte[] getUserInfo(){
        //认证
        new Authentication().verify();
        //鉴权
        new ResourcePermission().verify();
        //编码
        return new Encode().code();
    }
}

/**
 * @author maikec
 * @date 2019/5/14
 */
public class Authentication {
    public void verify() {
        System.out.println( "Authentication" );
    }
}

/**
 * @author maikec
 * @date 2019/5/14
 */
public class ResourcePermission {
    public void verify() {
        System.out.println( "ResourcePermission" );
    }
}

/**
 * @author maikec
 * @date 2019/5/14
 */
public class Encode {
    public byte[] code() {
        return "Hi Facade".getBytes();
    }
}

/**
 * @author maikec
 * @date 2019/5/14
 */
public class FacadeDemo {
    public static void main(String[] args) {
        UserInfoFacade facade = new UserInfoFacade();
        byte[] bytes = facade.getUserInfo();
        System.out.println( new String( bytes ) );

    }
}

附录

github.com/maikec/patt… 个人GitHub设计模式案例

声明

引用该文档请注明出处