【发布时间】:2014-11-12 18:14:33
【问题描述】:
class Message {
protected $body;
public function setBody($body)
{
$this->body = $body;
}
public function getBody()
{
return $this->body;
}
}
class ExtendedMessage extends Message {
private $some;
public function __construct($somedata)
{
$this->some = $somedata;
}
public function getBody()
{
return $this->some;
}
}
$a = new Message;
$b = new ExtendedMessage('text');
$a->getBody(); // NULL`
$b->getBody(); // text`
【问题讨论】:
-
欢迎来到 SO。这种问题最好在codereview.stackexchange.com 等资源上提出
标签: php oop design-patterns liskov-substitution-principle