<?php include_once '../../class/pattern/adapter.php'; $ps2Mouse = new SimplePs2Mouse(); // 建立一個ps/2介面的滑鼠 $ps2UsbAdapter = new Ps2UsbAdapter($ps2Mouse); // 將ps/2介面滑鼠接到轉接器中 // 現在ps2滑鼠可用usb介面操作 $ps2UsbAdapter->usb_connect(); $ps2UsbAdapter->usb_click(); $ps2UsbAdapter->usb_move();
} public function ps2_connect() { echo "PS/2 connect\n"; } } class Ps2UsbAdapter implements UsbMouse { private $ps2Mouse; public function __construct(Ps2Mouse $ps2Mouse) { $this->ps2Mouse = $ps2Mouse; } public function usb_click() { $this->ps2Mouse->ps2_click(); } public function usb_move() { $this->ps2Mouse->ps2_move(); } public function usb_connect() { $this->ps2Mouse->ps2_connect(); } } $ps2Mouse = new SimplePs2Mouse(); $ps2Adapter = new Ps2UsbAdapter($ps2Mouse); $ps2Adapter->usb_click(); $ps2Adapter->usb_move(); $ps2Adapter->usb_connect();