There is such a set of classes:
class A extends ParentA { public function someFn1() { $a = 1 + 3; echo $a; parent::someFn1() } public function someFn2() { $b = rand(10); echo $b; parent::someFn2() } } class B extends ParentB { public function someFn1() { $a = 1 + 3; echo $a; parent::someFn1() } public function someFn2() { $b = rand(10); echo $b; parent::someFn2() } } class C extends ParentC { public function someFn1() { $a = 1 + 3; echo $a; parent::someFn1() } public function someFn2() { $b = rand(10); echo $b; parent::someFn2() } } class D extends ParentD { public function someFn1() { $a = 1 + 3; echo $a; parent::someFn1() } public function someFn2() { $b = rand(10); echo $b; parent::someFn2() } } and so on. In this case: ParentA ... ParentD are the heirs of the class Parent
and A ... D methods someFn1, someFn1 and others have identical functionality in terms of code. But implementation in parent classes is different.
The Parent class itself:
class Parent { abstract public function someFn1(); abstract public function someFn2(); } Example of class ParentA:
class ParentA { public function someFn1() { echo "ParentA fn1" }; public function someFn2() { echo "ParentA fn2" }; } The functional is given only as an example.
Questions :
how to reorganize AD classes, without changing the Parent , ParentA -ParentD classes to avoid multiple copy-paste.
In general, the problem is this: the name of the class is one, but it must be inherited from various classes.
Example:
class SomeName extends ParentA { public function someFn1() { ... }; public function someFn2() { ... }; } where the heir to ParentA changes to another. However, this is an ideal case.