Façade Pattern
Façade Pattern에 대해 설명하는 페이지입니다.
Façade Pattern
Tags
Design Pattern, Java
1. Introduction
- Purpose
- Supplies a single interface to a set of interfaces within a system.
- Use When
- A simple interface is needed to provide access to a complex system.
- There are many dependencies between system implementations and clients.
- Systems and subsystems should be layered.
- Characteristics
- Provide a unified interface to a set of interfaces in a subsystem. It defines a higher-level interface that makes a subsystem easier to use.
- Does not prevent sophisticated clients from accessing the underlying classes.
- It doesn't add any functionality. It just simplifies interfaces.
- Benefits
- Hides the implementations of the subsystem from clients.
- makes the subsystem easier to use
- Promotes weak coupling between the subsystem and its clients
- allows changing the classes comprising the subsystem without affecting the clients
- Hides the implementations of the subsystem from clients.
2. How to Use (Example)
-
A set of interfaces
java1public class Class1 { 2 public void doSomething() { 3 System.out.print("Hello, "); 4 } 5} 6public class Class2 { 7 public void doSomething() { 8 System.out.print("World!"); 9 } 10} -
Façade
java1public class MyClass { 2 public void doSomething() { 3 Class1 c1 = new Class1(); 4 Class2 c2 = new Class2(); 5 c1.doSomething(); 6 c2.doSomething(); 7 } 8}
