dev-resources.site
for different kinds of informations.
Facade Pattern
Published at
10/4/2020
Categories
structural
pattern
designpatterns
java
Author
eidher
Main Article
Author
6 person written this
eidher
open
Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.
Participants
- Facade: knows which subsystem classes are responsible for a request. Delegates client requests to appropriate subsystem objects.
- Subsystem classes: implement subsystem functionality. Handle work assigned by the Facade object. Have no knowledge of the facade and keep no reference to it.
Code
public class Main {
public static void main(String[] args) {
Facade facade = new Facade();
facade.methodA();
facade.methodB();
}
}
public class SubSystemOne {
public void methodOne() {
System.out.println(" SubSystemOne Method");
}
}
public class SubSystemTwo {
public void methodTwo() {
System.out.println(" SubSystemTwo Method");
}
}
public class SubSystemThree {
public void methodThree() {
System.out.println(" SubSystemThree Method");
}
}
public class SubSystemFour {
public void methodFour() {
System.out.println(" SubSystemFour Method");
}
}
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("\nmethodA() ---- ");
one.methodOne();
two.methodTwo();
four.methodFour();
}
public void methodB() {
System.out.println("\nmethodB() ---- ");
two.methodTwo();
three.methodThree();
}
}
Output
methodA() ----
SubSystemOne Method
SubSystemTwo Method
SubSystemFour Method
methodB() ----
SubSystemTwo Method
SubSystemThree Method
structural Article's
11 articles in total
Top Architect and Structural Engineer for Custom Designs
read article
Proxy
read article
PRISTON STRUCTURAL SYSTEMS
read article
Proxy Pattern
read article
Flyweight Pattern
read article
Facade Pattern
currently reading
Composite Pattern
read article
Bridge Pattern
read article
Adapter Pattern
read article
Decorator Pattern
read article
Main Design Patterns
read article
Featured ones: