šŸ§° Developerā€™s toolbox: šŸ”Œ Adapter Design Pattern

Vee Lesyk
Dots and Spaces
Published in
1 min readAug 18, 2019

Adapter pattern lets you wrap an otherwise incompatible object in an adapter to make it compatible with another class.

Wikipedia says:

In software engineering, the adapter pattern is a software design pattern that allows the interface of an existing class to be used as another interface. It is often used to make existing classes work with others without modifying their source code.

Real world example

Consider that you have some pictures in your memory card and you need to transfer them to your computer. In order to transfer them you need some kind of adapter that is compatible with your computer ports so that you can attach memory card to your computer. In this case card reader is an adapter. Yet another example would be a translator translating words spoken by one person to another.

Github repo: link.

Demo example:

Power adapter: a two pronged legged US plug canā€™t be connected to an EU outlet, it needs to use a power adapter.

Swift

Adapter.swift

TypeScript

Adapter.ts
Adapter

P.S. We would be happy to see comments according to mistakes & typos.

--

--

Vee Lesyk
Dots and Spaces

#h+ #livemoredomore Adventurer. Unique experience wizard. Maker of things. Convergence commander. Information warlock. Problem solver. System: ā˜‰; Planet: ā™.