Last active
October 22, 2015 12:45
-
-
Save harunyasar/0b5c8cc00df52152c70b to your computer and use it in GitHub Desktop.
Email Sender sınıfı için Loose Coupling örneği
This file contains 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 UserProviderInterface { | |
public function findUserById($id); | |
} | |
class UserProvider implements UserProviderInterface { | |
private $db; | |
public function __construct(MySQLConnection $db) | |
{ | |
$this->db = $db; | |
} | |
public function findUserById($id) | |
{ | |
return $this->db->execute('SELECT * FROM users WHERE id = ?', array($id)); | |
} | |
} | |
class EmailSender { | |
private $users; | |
public function __construct(UserProviderInterface $users) | |
{ | |
$this->users = $users; | |
} | |
public function send($id, $subject, $message) | |
{ | |
$user = $this->users->findUserById($id); | |
// E-Posta gönderme işlemi | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment