Facade Design Pattern — 3 Minute Series

Provide an easy entry to your client.

Elric Edward
1 min readSep 20, 2022
We create an easy entry for your client.
Photo by Karim MANJRA on Unsplash

_00 / Concept

The goal is to provide a simple interface to your end users. As your users, they don’t need to know how complex the logic it will be. Again, you can take SDK as an example. The SDK should be handy even if the users don’t know the underlying code.

_01 / Key Roles

In the following code sample, the Browser will encapsulate the detail logic about surfing on the internet. User can focus on what they want instead of browser logic.

// encapsulate the logic
class Browser {
...
constructor(DNS, TCP, HTTP, DOM) {
this.DNS = DNS
this.TCP = TCP
this.HTTP = HTTP
this.DOM = DOM
}
go(url) {
this.DNS.search(url)
this.TCP.connect()
this.HTTP.connect()
this.DOM.render()
}
}
// client
const browser = new Browser(...)
browser.go("https://www.google.com/")

_02 / Trade-offs

🟢 Easy for client to use, quite friendly.
🟢 Isolate your subsystem.
🔴 Once you adding more things, you will create a god like class.
🔴 You would have several reasons to modify your god like class.

--

--