Ashish Patel: Notes

Atom feed

Recently added: Introduction, Abstraction, Xunit, Publisher subscriber pattern, Request reply pattern

Adapter Pattern

Adapter Pattern is an abstraction for nasty or 3rd party code, you need in your main clean codebase.

It is basically a wrapper around a particular class or object, which provides a different API and utilizes the object’s original one in the background.

Use Cases

// index.js
import { v4 as uuidv4 } from 'uuuid'

console.log(uuidv4()) // without adapter pattern
// uuid.js
import { v4 as uuidv4 } from 'uuuid'

class uuid {
  generate() {
    return uuidv4()
  }
}

export default new uuid()
// App.js
import uuid from './uuid

console.log(uuid.generate())

Created 2019-01-23T11:57:03+05:30, updated 2020-08-23T11:04:17+05:30 · History · Edit