Java中的门面设计模式,非常有用!
Posted Java技术栈
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java中的门面设计模式,非常有用!相关的知识,希望对你有一定的参考价值。
public class MainBoard {
public void start(){
System.out.println("main board is open");
}
public void end(){
System.out.println("main board is close");
}
}
显卡的启动和关闭:
public class VideoCard {
public void start(){
System.out.println("video card is open");
}
public void end(){
System.out.println("video card is close");
}
}
网卡的启动和关闭:
public class NetCard {
public void start(){
System.out.println("net card is open");
}
public void end(){
System.out.println("net card is close");
}
}
将上面的操作封装到一个门面之中:
public class FacadeInstall {
private MainBoard mainBoard;
private NetCard netCard;
private VideoCard videoCard;
public FacadeInstall(){
mainBoard = new MainBoard();
netCard = new NetCard();
videoCard = new VideoCard();
}
public void start(){
mainBoard.start();
netCard.start();
videoCard.start();
}
}
测试类:
public class FacadeTest {
public static void main(String[] args) {
FacadeInstall facadeInstall = new FacadeInstall();
facadeInstall.start();
}
}
运行结果:
main board is open
net card is open
video card is open
filterChain.doFilter(request.getRequest(), response.getResponse())
而这两个参数的源码如下:
public HttpServletRequest getRequest() {
if (facade == null) {
facade = new RequestFacade(this);
}
return facade;
}
public HttpServletResponse getResponse() {
if (facade == null) {
facade = new ResponseFacade(this);
}
return (facade);
}
https://my.oschina.net/u/3441184/blog/889706
- END -
点击「阅读原文」和栈长学更多~
以上是关于Java中的门面设计模式,非常有用!的主要内容,如果未能解决你的问题,请参考以下文章