Façade Design Pattern in Swift, and Its Important Use-Cases
One Gang of Four’s piece that I still use in every project
Being a junior-ish developer, have you ever been told by your lead something like: Hey, just hide it behind a façade? I have, and—guess what?—it was one of the most important lessons in my programmer’s career. To understand why, let’s first take a look at what the Façade pattern is.
Theory
Façade is one of the so-called structural design patters from the Gang of Four’s catalogue. Its purpose is to simplify the interface of some subsystem.
If you like diagrams, here’s the UML class diagram from Wikipedia:
On the right side of the diagram, there is a nominal complex subsystem. It can be a framework, a Swift package, or another library, third-party or not. It also can be a part of your own app. The system has an API, consisting of multiple methods, probably with excessive signatire. It may even consist of multiple protocols or classes.
Typically, you only need a handful of available methods and classes, or you want to have simpler method signatures…