这可能是一个基本的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";
}
}
Run Code Online (Sandbox Code Playgroud)
在上述情况下,我没有告诉TextInput到implement HtmlElementInterface,难道不是吗?
不,TextInput 是HTMLElement这是一个HtmlElementInterface