Skip to content

Design pattern

Bad design

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/4f63cf0b-054a-4754-9df7-a03fcde33217/Untitled.png

Here, if we want to increase minions, it will increase if/ else in our code.

Adapter Pattern

Adapter is basically mapper between these different functions.

A possible example:

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/705a4fe2-b9e6-44d9-a390-4c49e773e916/Untitled.png

A better an generalised solution to adapter design pattern would be:

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/1f7f503e-9821-4448-ac85-79cb23728ccf/Untitled.png

Notice here the changes made to adapter object will make changes to Parent class ( achieved using getter and setter method)→ this is actually implementation of decorator pattern

Facade Pattern:

Basically providing an simple API. By adding one more layer of abstraction.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e4567e4c-ed2a-4397-aeb9-9a2c84f1b931/Untitled.png

Observer Pattern

Here observable notify the observer whenever any change occurs, rather than the observer polling and asking if any changes has occured.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ec1de265-f80e-483e-8343-16f2f1f62e76/Untitled.png

Safe traders.

Refactoring