这可能是一个基本的OOP问题,但我不确定答案,并且在Google搜索中找不到有用的东西(即第一页,当然)
如果我有一个类是实现接口的另一个类的子类,我的子类是自动成为接口的实现,还是我必须特别说明它是?所以
interface HtmlElementInterface {
public function getName();
}
abstract class HtmlElement implements HtmlElementInterface {
protected $_name;
public function __construct($name) {
$this->_name = $name;
}
public function getName() {
return $this->_name;
}
abstract public function __toString();
}
class TextInput extends HtmlElement {
public function __toString() {
return "<input type='input' name='{$this->_name}' id='{$this->_name}' />n";
}
}
在上面的情况下,我不必告诉TextInput
implement HtmlElementInterface
,对吗?
不,TextInput
是一个HTMLElement
,这是一个HtmlElementInterface
不,你没有。这隐含着HtmlElementInterface
实施。