外觀模式(Facade)定義:爲子系統中的一組接口提供一個一致的界面,些模式定義了一個高層接口。這個接口使得這一子系統更加容易使用。
java
類型:結構型模式git
順口溜:適裝橋組享代外github
package com.amosli.dp.structural.facade; public class Facade { SubsystemOne one; SubsystemTwo two; SubsystemThree three; public Facade() { one = new SubsystemOne(); two = new SubsystemTwo(); three = new SubsystemThree(); } public void methodA() { System.out.println("group A:"); one.operation1(); two.operation2(); } public void methodB() { System.out.println("group B:"); three.operation3(); } } package com.amosli.dp.structural.facade; public class SubsystemOne { public void operation1(){ System.out.println("deal 1 part..."); } } package com.amosli.dp.structural.facade; public class SubsystemTwo { public void operation2(){ System.out.println("deal 2 part..."); } } package com.amosli.dp.structural.facade; public class SubsystemThree { public void operation3(){ System.out.println("deal 3 part..."); } } package com.amosli.dp.structural.facade; public class Client { public static void main(String[] args) { Facade facade = new Facade(); facade.methodA(); facade.methodB(); } }
在如下狀況下能夠考慮使用外觀模式:spa
本系列文章源碼地址,https://github.com/amosli/dp 歡迎Fork & Star !!設計