Member-only story
The Facade Design Pattern In Swift
A quite common structural design pattern presented through a practical example.
The facade (spelled façade) design pattern is a pretty common pattern that’s usually easy to adopt. Having taken its name from the front side in architecture and buildings that hide their internals, chances are that you have already put it in motion, even without realizing it.
What the facade pattern suggests could be summarized in plain words to this:
When there is a combination of APIs necessary to use but doing so tends to be a difficult or complicated task, then implement simpler intermediate APIs if possible that are more straightforward and easier for your code to work with, and hide all complexities behind these new APIs.
Note: Even though the facade design pattern is mostly common in Object-Oriented Programming and refers to classes, in this text I make the context more general and referring to APIs instead, including under this term classes, structs, enums, protocols, functions, and everything else we meet in Swift; not just classes. Swift is not a strict OOP language, and facade can…