Appearance Mode
definition
Facade Pattern: Provides a consistent interface for a set of interfaces in a subsystem. This pattern defines a high-level interface that makes the subsystem easier to use.
Structure diagram
specific code
Subsystems:
SubSystemOne class
public class SubSystemOne { public void methodOne(){ System.out.println("子系统方法一!"); }}12345
SubSystemTwo class:
public class SubSystemTwo { public void methodTwo(){ System.out.println("子系统方法二!"); }}12345
SubSystemThree class:
public class SubSystemThree { public void methodThree(){ System.out.println("子系统方法三!"); }}12345
SubSystemFour class:
public class SubSystemFour { public void methodFour(){ System.out.println("子系统方法四!"); }}12345
Appearance class:
It needs to understand the methods of all subsystems and combine them for external calls
public class Facade { private SubSystemOne one; private SubSystemTwo two; private SubSystemThree three; private 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(); four.methodFour(); } public void methodB(){ System.out.println("方法组B"); two.methodTwo(); three.methodThree(); }}
Tags
Technical otaku
Sought technology together
0 Comments