3 Design Patterns you should know

Ramazan Ramazanov
3 min readOct 15, 2020

--

In order to build your technical skillset in a professional sphere software engineers start with Language Proficiency, then continue with Data Structures & Algorithms and Design Patterns.

A design pattern is a description or template for how to solve a problem that can be used in many various situations and it is not a finished design that can be transformed directly into code. Development process can be fastened with the use of design patterns as they provide tested, proven development paradigms. They help to prevent subtle issues that can cause major problems and improves code readability for coders who are familiar with the patterns.

Singleton

The first design pattern that I think is important to know is called Singleton. It is part of creational design patterns that are all about class installation and can be divided further into class-creation patterns and object-creational patterns.

singleton design pattern

Singleton is a design pattern that restricts the instantiation of a class to one object. Usually, the goal is to manage global application state. Singletons are useful in situations where system-wide actions need to be coordinated from a single central place. Also singletons reduce the need for global variables in Javascript.

const Singleton = (function() {
const instance
function createInstance(){
const object = new Object('I am the instance')
return object
}
return {
getInstance: function() {
if (!instance) {
instance = createInstance()
}
return instance
}
}
})()
function run(){
const instance1 = Singleton.getInstance()
const instance2 = Singleton.getInstance()
alert('Same instance?' + (instance1 === instance2))
}

Bridge

The Bridge design pattern should “decouple an abstraction from its implementation so that the two can vary independently.” It allows two components, a client and a service, to work together with each component having its own interface. Bridges are quite beneficial in event-driven applications, which are quite common in JavaScript. Considering that fact, it’s surprisingly one of the most underused design patterns.

An example of the Bridge design pattern is an application (the client) and a database driver (the service).

bridge design pattern

Facade

The Facade design pattern defines a unified, higher-level interface to wrap a complicated set of interfaces in a subsystem. It protects client code from sophisticated functionality in one or more subsystems by providing an interface or API to work with that is better and significantly easier to use.

Facade design patters are usually used when we want to simplify the interface to access several external/internal APIs in multiple subsystems or when we are dealing with on progress API that we want to provide a consistent API to the client code. You can pretty much call any form of abstraction a facade.

facade design pattern

There are many other design patterns and they allow developers to communicate using well-known, well understood names for software interactions. But I think these 3 design patterns are the ones that every developer should know.

--

--

No responses yet