Reputation: 6207
given this code:
class EmailHander
{
public $mailer;
public function __construct()
{
$mailer = new PHPMailer();
}
public function getEmail ($name)
{
return new EmailTemplate ($name, $this);
}
}
class EmailTemplate
{
public $body, $subject, $handler;
public __construct ($name, EmailHander $handler)
{
require ($name.'.html');
$this->handler = $handler;
}
public function send ($target)
{
$this->handler->mailer->send ($target, ......);
}
}
there is an EmailHandler
which deals with the mailer, and many EmailTemplates
which represents the emails. So,
$handler = new EmailHandler();
$email = $hander->getEmail ('subScribe');
$email->send('[email protected]');
but this is might bad. The EmailHandler
produces an EmailTemplate
. But EmailTemplate
refers to EmailHandler
, so this is a circular thing, is that good or bad?
Upvotes: 1
Views: 55
Reputation: 385325
There is no circular dependency in this code. There is a one-way dependency from an email to its handler; doesn't matter that the handler set up the dependency.
Upvotes: 2