Problem

A new component or dependency is not compatible with the current system architecture.

Solution

Convert the interface for the incompatible object into something that the rest of the system expects and understands. Wrap an existing class with a new interface.

Related Patterns

Discussion

Just as we use adapters for hardware, software often needs an adapter to ease communication between the parts. The Adapter pattern is about creating an intermediary interface object that we can use to talk to incompatible or legacy components.

Examples

Many adapters are found in the real world. Display cables are found in several variations (VGA, DVI, DisplayPort, HDMI). The display device that you would like to connect to does not always have the same port as your device. We use adapters to enable the use of these cables and displays.

Code

A database interface in any language is an adapter for systems that aren't directly compatible.

$db = new OracleOCI('localhost', 'sys', 'password', 'schema');

$query = "select * from DUAL";
$results = $db->query($query);
while($data = oci_fetch_object($results)) echo $data->DUMMY;