依赖反转原则
class Mailer {
// Implementation...
}
class NotifySubscriber {
public function notify($emailTo) {
$mailer = new Mailer();
$mailer->send('Thank you for...', $emailTo);
}
}interface MailerInterface {
// Implementation...
}
class Mailer implements MailerInterface {
// Implementation...
}
class NotifySubscriber {
private $mailer;
public function __construct(MailerInterface $mailer) {
$this->mailer = $mailer;
}
public function notify($emailTo) {
$this->mailer->send('Thank you for...', $emailTo);
}
}最后更新于