这可能是一个基本的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
,是吗?
答案 0 :(得分:5)
不,你没有。这隐含地是HtmlElementInterface
实施。
答案 1 :(得分:5)
不,TextInput
是HTMLElement
,HtmlElementInterface