php - How to solve this without multiple inheritance? -
i have class named controller_home
. should inherit controller_permissions
, controller_template
. class prefixed controller_
must inherit controller
class.
if multiple inheritance supported in php (my case), this:
class controller_home extends controller_permissions, controller_template {
and controller_permissions
, controller_template
:
controller_permissions extends controller { controller_template extends controller {
now need this:
class controller_home extends controller_template { class controller_permissions extends controller_template { controller_template extends controller {
okay, works!
now need use controller_template
without permissions (in controller_permissions
).
how without duplicating code? don't want class controller_templatewithoutpermissions
.
controllers, templates , permissions example.
the common alternative multiple inheritance use composition. makes relationship "has a" opposed "is a" relationship. ie in example above might have controllerhome inherit controllertemplate hold controllerpermissions variable. way controllerhome is a controllertemplate , has a controllerpermissions.
Comments
Post a Comment