, , , , - :
interface Connection_Interface
{
public function connect();
public function disconnect();
public function exec($sql);
}
class Connection implements Connection_Interface
{
public function __construct($host, $username, $password, $database);
public function connect();
public function disconnect();
public function exec($sql);
}
, :
class Connection_Multiple implements Connection_Interface
{
protected $_connections = array();
public function __construct();
public function add(Connection $connection);
public function connect();
public function disconnect();
public function exec($sql)
{
return $connection->exec($sql);
}
}
Since both a single connection and several connection classes implement the same interface, you can use either the exact same way.
source
share