![图片[1]-java门面模式的优点-uusu优素-乐高,模型,3d打印,编程](https://uusu.cn/wp-content/uploads/2025/01/1634541477746462.png)
1、减少系统的相互依赖。如果不使用立面模式,外部访问将直接深入子系统。
这是一种强烈的耦合关系,这是系统设计无法接受的。门面模式的出项很好地解决了这个问题,所有的依赖都是对门面对象的依赖,与子系统无关。
2、提高了灵活性。依赖减少,灵活性自然提高。
3、提高安全性。想让你访问子系统的业务就打开那些逻辑,不在门面打开的方法就不能访问。
实例
packagecom.sl.demo.facade;
/**
*电脑(门面角色)
*@authorpengkun
*
*/
publicclassComputer{
//包含子系统
privateCPUcpu;
privateGraphicsCardgraphicsCard;
privateMemorymemory;
publicComputer(){
super();
this.cpu=newCPU();
this.graphicsCard=newGraphicsCard();
this.memory=newMemory();
}
//开启
publicvoidstart(){
System.out.println("电脑开启了。。。。");
cpu.start();
graphicsCard.start();
memory.start();
}
//关闭
publicvoidstop(){
System.out.println("电脑关闭了。。。。");
cpu.stop();
graphicsCard.stop();
memory.stop();
}
}原文来自:https://www.py.cn © 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END

















































暂无评论内容