- 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:

- Cross-platform Desktop Application Development:Electron,Node,NW.js,and React
- Java深入解析:透析Java本質(zhì)的36個(gè)話題
- 零基礎(chǔ)學(xué)MQL:基于EA的自動(dòng)化交易編程
- 數(shù)據(jù)結(jié)構(gòu)與算法分析(C++語(yǔ)言版)
- SQL 經(jīng)典實(shí)例
- Spring Boot+Vue全棧開(kāi)發(fā)實(shí)戰(zhàn)
- Android開(kāi)發(fā)三劍客:UML、模式與測(cè)試
- Arduino計(jì)算機(jī)視覺(jué)編程
- 寫給大家看的Midjourney設(shè)計(jì)書
- 從“1”開(kāi)始3D編程
- SQL Server 2014 Development Essentials
- Java程序設(shè)計(jì)
- C/C++程序設(shè)計(jì)教程
- 區(qū)塊鏈原理、設(shè)計(jì)與應(yīng)用
- C語(yǔ)言從入門到精通(第4版)