5
In Wordpress I am creating a custom screen in the administration area.
That’s why I’m extending my class customProductsListTable
the class WP_List_Table
:
class customProductsListTable extends WP_List_Table
I have another class for another custom screen that extends the same class WP_List_Table
:
class customReviewsListTable extends WP_List_Table
The problem is that in the classes customProductsListTable
and customReviewsListTable
created some methods that are common and that do not exist in the class WP_List_Table
.
So we have the following scenario:
The classes
customReviewsListTable
andcustomProductsListTable
do overwrite of some class methodsWP_List_Table
, but the code behaves differently in each class.The classes
customReviewsListTable
andcustomProductsListTable
have new methods but with the same behavior.
Clearly I am duplicating code in both classes, but we cannot in PHP inherit more than one class.
How to solve the code duplication problem?
Thank you. Yes, the intermediate class can be abstract with the abstract methods in the cases that have different behavior and the others that have equal behavior, will not be signed as
abstract
. I don’t want the middle class to be instantiated either.– Filipe Moraes
another way to solve would be to create one or more interfaces for these methods.
– Rodrigo