يسمح نمط Adapter للكائنات ذات الواجهات غير المتوافقة بالعمل معاً من خلال تغليف أحدها بالواجهة التي يتوقعها الآخر. يعمل كمترجم بين واجهتين، مما يتيح التكامل دون تعديل الكود الموجود.
ما يفعله نمط Adapter
ADAPTER → convert one interface into another that a client expects (a "translator"):
→ wrap an object whose interface is INCOMPATIBLE, exposing the interface the client needs
→ the adapter translates calls/data between the two interfaces
→ makes incompatible things work together WITHOUT changing either's code
مثال
{ () { } }
{
() { . = thirdParty; }
() { ..(msg); }
}
logger = ( ());
logger.();
