Skip to content

Instantly share code, notes, and snippets.

@harunyasar
Last active October 22, 2015 12:45
Show Gist options
  • Save harunyasar/0b5c8cc00df52152c70b to your computer and use it in GitHub Desktop.
Save harunyasar/0b5c8cc00df52152c70b to your computer and use it in GitHub Desktop.
Email Sender sınıfı için Loose Coupling örneği
<?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