๐“๐ข๐ญ๐ฅ๐ž๐Ÿ”Œ๐€๐๐š๐ฉ๐ญ๐ž๐ซ ๐ƒ๐ž๐ฌ๐ข๐ ๐ง ๐๐š๐ญ๐ญ๐ž๐ซ๐ง

โ‰๏ธ ๐ˆ๐ง๐ญ๐ž๐ง๐ญ
Allows classes work together although they have incompatible interfaces.

๐Ÿคฏ๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ
Have you ever tried to integrate two existing systemโ€ฆbut they just donโ€™t fit together?

๐ŸŒ ๐‘๐ž๐š๐ฅ-๐–๐จ๐ซ๐ฅ๐ ๐’๐œ๐ž๐ง๐š๐ซ๐ข๐จ
For example a drawing editor provides users actions such as: draw and arrange of graphical elements (lines, text, etc.). This editor provides an abstract class named Shape. Classes for elementary shapes like LineShape and PolygonShape are easy to implement, but TextShape is not because it displays and edits text. Meanwhile, there is a toolkit class which already implements displaying and editing text named TextView, but it was not designed to work with Shape classes. Therefore, we cannot use TextView and Shape interchangeably. How can we cope with this issue?

๐ŸŽฏ ๐’๐จ๐ฅ๐ฎ๐ญ๐ข๐จ๐ง โ€” ๐€๐๐š๐ฉ๐ญ๐ž๐ซ ๐๐š๐ญ๐ญ๐ž๐ซ๐ง
We can define TextShape so that it adapts the TextView to Shape. We can do it in one of two ways:
1๏ธโƒฃ๐ˆ๐ง๐ก๐ž๐ซ๐ข๐ญ๐š๐ง๐œ๐ž
2๏ธโƒฃ๐‚๐จ๐ฆ๐ฉ๐จ๐ฌ๐ข๐ญ๐ข๐จ๐ง

๐Ÿ’Ž๐‘๐ž๐ฅ๐š๐ญ๐ž๐ ๐๐š๐ญ๐ญ๐ž๐ซ๐ง๐ฌ
Bridge has a structure similar to an object adapter, but Bridge has a different intent: It is meant to separate an interface from its implementation so that they can be varied independently. An Adapter is meant to change the interface of an existing object. Decorator enhances another object without changing its interface. A decorator is thus more transparent to the application than an adapter is. As a consequence, Decorator supports recursive composition, which isn't possible with pure adapters.

๐Ÿ“‚ ๐‚๐จ๐๐ž ๐„๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž
See it in action:
๐Ÿ‘‰ GitHub - (https://github.com/shirin-monzavi/AdapterSample)

โ“๐–๐ก๐ข๐œ๐ก ๐๐ž๐ฌ๐ข๐ ๐ง ๐ฉ๐š๐ญ๐ญ๐ž๐ซ๐ง ๐๐จ ๐ฒ๐จ๐ฎ ๐ฌ๐ญ๐ซ๐ฎ๐ ๐ ๐ฅ๐ž ๐ฐ๐ข๐ญ๐ก ๐ญ๐ก๐ž ๐ฆ๐จ๐ฌ๐ญ?

๐Ÿ‘‡ Iโ€™d love to hear your thoughts!