Adapter pattern ช่วยให้อ็อบเจ็กต์ที่มี interface เข้ากันไม่ได้ ทำงานร่วมกันได้ด้วยการห่อหุ้มตัวหนึ่งด้วย interface ที่อีกตัวคาดหวัง มันทำหน้าที่เป็นตัวแปลภาษาระหว่างสอง interface ช่วยให้รวม integrate ได้โดยไม่ต้องแก้ไขโค้ดที่มีอยู่
Adapter pattern ทำอะไร
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.();
