Skip to content

Instantly share code, notes, and snippets.

@Vijaysinh
Forked from Ideneal/UserDB.php
Last active September 16, 2021 11:21
Show Gist options
  • Save Vijaysinh/b16f266af56666e8c0cec22778e2a817 to your computer and use it in GitHub Desktop.
Save Vijaysinh/b16f266af56666e8c0cec22778e2a817 to your computer and use it in GitHub Desktop.
<?php
//Dependency Inversion SOLID Principle
interface DBConnectionInterface {
public function connect();
}
class MySQLConnection implements DBConnectionInterface {
public function connect() {
echo "MySql connect";
}
}
class OracleConnection implements DBConnectionInterface {
public function connect() {
echo "Oracle connect";
}
}
class UserDB {
private $dbConnection;
public function __construct(DBConnectionInterface $dbConnection) {
$this->dbConnection = $dbConnection->connect();
}
public function store() {
}
}
$object = new UserDB(new OracleConnection());
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment