【发布时间】:2012-02-06 00:14:43
【问题描述】:
我想修改 parent 的 $item,然后,让 parent 运行其余的过程。怎么做? (我不能修改父类,它会经常通过软件更新来更新。另外请注意,$item 是函数内部的变量,它不是 parent->var)
Class Parent{
function __constructor(){....}
function save(){
$items = get_items($id, $this->var);
// process the data and save
}
}
Class Child extends Parent{
function __constructor(){
parent::__construct();
}
function save(){
$items = get_items($id, $var)// if.. then $var=$this->var, else $var=$something_else
// precess data and save
}
}
【问题讨论】:
-
这似乎是第三方 Parent 类的糟糕设计。任何解决方案都意味着代码重复或变通的解决方法,这两种方法都会在升级时出现维护问题。这是哪个包的?