Klasy SubscriptionMail i NotifiactionMail dziedziczą po abstrakcyjnej klasie Mail, która ma prywatną składową $_transport dlaczego te klasy wywołują prywatną składową rodzica w metodach send ?
/** * Interface for mailer implementations * */ interface MailTransport { /** * Send email * */ public function send($from, $to, $body); } class SendMailTransport implements MailTransport { public function send($from, $to, $body) { //send email using sendmail } } class SmtpTransport implements MailTransport { public function send($from, $to, $body) { //send email using SMTP } } /** * Objects representing an email * */ abstract class Mail { /** * Mail transport implementation * * @var MailerTransport */ private $_transport; /** * Email body * * @var string */ private $_body; /** * Recipient * * @var string */ private $_to; /** * Constructor * * @param MailerTransport $imp */ public function __construct(MailerTransport $imp) { $this->_transport = $imp; } /** * Get the email body * * @param string $string */ public function getBody() { return $this->_body; } /** * Set the email body * * @param string $string */ public function setBody($string) { $this->_body = $string; } /** * Set the email recipient * * @param string $address */ public function getTo() { return $this->_to; } /** * Set the email recipient * * @param string $address */ public function setTo($address) { $this->_to = $address; } /** * Get the sender address * * @return string */ public function getFrom() { return $this->_from; } /** * Set the sender address * * @param string $address */ public function setFrom($address) { return $this->_from; } } { /** * Check if the value is valid * * @param mixed $mixed * @return bool */ public function send() { if(!$this->_transport->send($this->getFrom(), $this->getTo(), $this->getBody())) //wywołanie prywatnej składowej _transport z klasy rodzica Mail ? { //a failed notice is not that much of isssue } } /** * Format the body as a notice * * @return string */ public function getBody() { return "Notice: " . parent::getBody(); } } { /** * Check if the value is valid * * @param mixed $mixed * @return bool */ public function send() { if(!$this->_transport->send($this->getFrom(), $this->getTo(), $this->getBody())) //wywołanie prywatnej składowej _transport z klasy rodzica Mail ? { //if it fails, we should handle that throw new Exception('Failed to send subscription email'); } } } $mail = new SubscriptionMail(new SmtpTransport());