mirror of
https://github.com/wataridori/solid-php-example.git
synced 2024-12-12 14:17:54 +00:00
49 lines
586 B
PHP
49 lines
586 B
PHP
<?php
|
|
// Dependency Inversion Principle Violation
|
|
class Mailer
|
|
{
|
|
|
|
}
|
|
|
|
class SendWelcomeMessage
|
|
{
|
|
private $mailer;
|
|
|
|
public function __construct(Mailer $mailer)
|
|
{
|
|
$this->mailer = $mailer;
|
|
}
|
|
}
|
|
|
|
// Refactored
|
|
interface Mailer
|
|
{
|
|
public function send();
|
|
}
|
|
|
|
class SmtpMailer implements Mailer
|
|
{
|
|
public function send()
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
class SendGridMailer implements Mailer
|
|
{
|
|
public function send()
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
class SendWelcomeMessage
|
|
{
|
|
private $mailer;
|
|
|
|
public function __construct(Mailer $mailer)
|
|
{
|
|
$this->mailer = $mailer;
|
|
}
|
|
}
|