-
-
Save Vijaysinh/b16f266af56666e8c0cec22778e2a817 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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