
class SubSystemOne{ public void MethodOne(){ System.out.println("子系统方法一"); }}class SubSystemTwo{ public void MethodTwo(){ System.out.println("子系统方法二"); }}class SubSystemThree{ public void MethodThree(){ System.out.println("子系统方法三"); }}外观类:
class Facade{ SubSystemOne one; SubSystemTwo two; SubSystemThree three; SubSystemFour four; public Facade(){ one=new SubSystemOne(); two=new SubSystemTwo(); Three=new SubSystemThree(); four=new SubSystemFour(); } public void MethodA(){ System.out.println("方法A"); one.MethodOne(); two.MethodTwo(); three.MethodThree(); } public void MethodB(){ System.out.println("方法B"); two.MethodTwo(); }}
客户端调用static void main(String[] args){ Facade facade=new Facade(); facade.MethodA(); facade.MethodB();}首先,在设计之初,应该有意识的将不同的两个层分离,比如经典的三层架构,就需要考虑在数据访问层和业务逻辑层...,层与层之间建立外观Facade
其次,在开发解读,子系统往往因为不断的重构演化而变的相当复杂,增加外观Facade可以提供一个简单的接口,减少它们之间的依赖
第三,在维护一个遗留的大型系统,可能已经非常难以维护和扩展了。
外观模式什么时候用:

外观模式应用实例
799

被折叠的 条评论
为什么被折叠?



