【发布时间】:2014-09-18 00:33:39
【问题描述】:
我有 2 个类 Node 和 ChildNode,ChildNode 扩展了 Node。父级中有属性:
class Node {
protected $discount;
public function __construct($discount) {
$this->discount = $discount;
我在那里像整数值一样使用它,在 ChildNode 中我需要保存整数值数组
class ChildNode extends Node {
public function __construct(Array $discount) {
$this->discount = $discount;
这样正常吗?
【问题讨论】:
-
为什么需要继承?您的某个值在继承树中具有不同的类型,因此您可能必须覆盖父类的所有方法才能使用它。您可以使用接口构建继承树并通过不同的类实现它们。
标签: php oop polymorphism