I'm wondering what should be done in the case of needing Roles or Traits but in a classical inheritance environment. I have stemming of a class down two roads, both of which stem from a root class, however, I want to link the diverged classes on the two roads together to share the same functionality. See below:
+-- Base
+-- Base_Processor
| +-- Base_Processor_Request
| +-- Base_Processor_Request_Ajax
+-- Base_Impl
+-- Base_Impl_MyImpl
+-- Base_Impl_MyImpl_Processor (extends from Base_Processor)
+-- Base_Impl_MyImpl_Processor_Request (extends from ??)
+-- Base_Impl_MyImpl_Processor_Request_Ajax (extends from ??)
What would be the best way to link Base_Impl_MyImpl_Processor_Request and Base_Processor_Request together while still extending from Base_Impl_MyImpl_Processor, and also link Base_Impl_MyImpl_Processor_Request_Ajax in the same fashion.
Thanks in advanced.
I agree 100% with Alex Burtsev's comment - that many levels of inheritance looks like a dependency nightmare (and, as you're discovering, rather difficult to reuse particular bits of code across classes when you use inheritance that much).
Typically I wouldn't expect trait classes to be plugged into a heirarchy - to my mind, traits are standalone concepts which define variations across implementation details, and therefore only belong to an interface rather than being derived from a base class
If this is existing code and you have multiple elements which you need to reuse among different derived classes, I think it would make more sense to split those out to separate classes which are not related to your heirarchy at all.
It would seem that Processor
, Request
and Ajax
could better serve you as separate entities.