Common Design Patterns — Part 1. Facade and Adapter

Aqua Education
Web Architects
Published in
2 min readAug 7, 2023

In my previous article Introduction to Design Patterns, I have explained why it’s so important to learn design patterns. Some people might feel intimidated by design patterns and think of them as a really advanced topic that they will never need to touch. The reality is design patterns are everywhere and they are not as complicated as you think. In this and subsequent articles, I’m going to show you some of the most common design patterns.

Facade

Facade might be the simplest design pattern of all. By definition, a Facade is a class or group of classes that provide a simple and specific interface to a group of classes that have complex and general interfaces. One common usage of Facade is to layer systems. One great example of layering systems using Facade is the layers in MVC frameworks. In most MVC frameworks, you have the controller layer, model layer, and likely a business logic layer in between. Classes in each layer are Facade classes that define a high-level interface that makes the classes in the lower layer easier to use. Each layer forms Facades for the layer below it and serves the layer above it. You can even think of controllers as Facades that expose interfaces to frontend and other API clients.

Adapter

An equally simple pattern is the Adapter pattern. Adapter pattern is used to convert the interface of a class into another interface clients expect. The most common scenario where you will use Adapter is you need to utilize some 3rd-party code and you have an interface within your own system which you want the 3rd-party code to conform to. To achieve that, you can modify the 3rd-party code directly. However, this might not be possible because there is a rule in your team that no one should modify 3rd-party code. So what you can do is create an Adapter class that implements the interface and holds an instance of the 3rd-party class, and the methods of the Adapter class just delegate to the 3rd-party class.

--

--