親クラスに追加のものを追加したいと思います。 ソフトウェアのアップグレード時にすべての変更が消去されるため、親クラスは変更できません。だからクラスを拡張したい。親関数を繰り返さずに子クラスに追加することはできますか?親クラスのロジックと関数をどのように共有できますか?
class parent
{
public function __construct()
{
// lots of logic to hook up following functions with main software
}
// lots of parent functions
}
class child extends parent
{
function __construct()
{
// Is this going to share parent's logic and hook up with those actions?
// Or, should I repeat those logics?
parent::__construct();
// add child addicional logic
}
// child functions
// should I repeat parent's functions? I need the parent take child along all the jobs.
}
変更する部品をオーバーライドするだけで済みます。追加のコードに加えて親コードを実行する必要がある場合は、 'parent :: *'を呼び出す必要があります。親クラスのロジックを実行したい場合は、あなたのctorの場合は 'parent :: __ construct()'を呼び出す必要があります。あなたが過負荷にならない場合は、親からのメソッドを追加する必要はありません。 – Gordon