- Spring 5 Design Patterns
- Dinesh Rajput
- 286字
- 2021-07-08 09:59:39
Knowing when to use the Facade Pattern
Suppose you are designing a system, and this system has a very large number of independent classes and also has a set of services to be implemented. This system is going to be very complex, so the Facade pattern comes into the picture and reduces the complexities of the larger system and simplifies interactions of the client code with a set of classes from a subsystem of the large complex system.
Suppose you want to develop a bank enterprise application with a large number of services to perform a task, for example, AccountService for getting the Account by accountId, PaymentService for payment gateway services, and TransferService for the amount transfer from one account to another account. A client code of the application interacts with all these services to transfer money from one account to another account. This is how different clients interact with the amount transfer process of the bank system. As shown in the following figure, here you can see client code that directly interacts with the subsystem classes and client also should aware about the internal working of subsystem classes, so it is simply a violation of the SOLID design principles because client code is tightly coupled with the classes of subsystem of your banking application:

Rather than client code directly interacting with the classes of a subsystem, you could introduce one more interface, which makes the subsystems easier to use, as shown in the following figure. This interface is known as a Facade interface, it is based on the Facade pattern, and it is a simple way to interact with the subsystems:

- SPSS數據挖掘與案例分析應用實踐
- Responsive Web Design with HTML5 and CSS3
- Internet of Things with the Arduino Yún
- 高級C/C++編譯技術(典藏版)
- 教孩子學編程:C++入門圖解
- 重學Java設計模式
- UNIX Linux程序設計教程
- Android應用開發深入學習實錄
- 創意UI:Photoshop玩轉APP設計
- 區塊鏈架構之美:從比特幣、以太坊、超級賬本看區塊鏈架構設計
- 一步一步跟我學Scratch3.0案例
- WordPress Search Engine Optimization(Second Edition)
- Java并發實現原理:JDK源碼剖析
- Mastering Bootstrap 4
- HTML5 Game Development by Example:Beginner's Guide(Second Edition)