Skip to content

Instantly share code, notes, and snippets.

@joaorobertopb
Created January 5, 2019 20:18
Show Gist options
  • Save joaorobertopb/ffd6e2eb8e31e75b8e18fd3a5cbe9642 to your computer and use it in GitHub Desktop.
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.
<?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