Created
January 5, 2019 20:18
-
-
Save joaorobertopb/ffd6e2eb8e31e75b8e18fd3a5cbe9642 to your computer and use it in GitHub Desktop.
Exemplo de código PHP que utiliza o Dependecy Inversion Principle do SOLID.
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 | |
interface DBConnectionInterface | |
{ | |
public function connect(); | |
} | |
class MySQLConnection implements DBConnectionInterface | |
{ | |
public function connect() | |
{ | |
// ... | |
} | |
} | |
class OracleConnection implements DBConnectionInterface | |
{ | |
public function connect() | |
{ | |
// ... | |
} | |
} | |
class PasswordReminder | |
{ | |
private $dbConnection; | |
public function __construct(DBConnectionInterface $dbConnection) { | |
$this->dbConnection = $dbConnection; | |
} | |
// Faz alguma coisa | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment