[TYPO3-dev] SOLUTION (?) : Multiple XCLASS inheritance

Jerome Schneider typo3dev at ameos.com
Tue Feb 7 16:35:34 CET 2006


Hello community

I'm currently working on a solution to allow TYPO3 developpers to extend the 
same extension several times ( instead of just one time using XCLASS )


I call this reverse inheriting : here is an example.

Let's say somenone has developped an extension named 'forum', in a class 
named 'tx_forum_pi1'.

 class tx_forum extends pi_base
 {
  function main()
  {}

  /* some code */
 }


I need to extend this extension to add some specific behaviour. Assume this 
can't be done using hooks.
We decide to name our extension tx_forum_extended
If I do so using XCLASS, my work will be a dead-end, as no one will be able 
to extend my work : XCLASS can't be extended

Here is the idea : instead of asking to Typo3 to handle my xclass rather 
than tx_forum, we could ask typo3 to handle tx_forum, heriting from our 
extending extension :


 tx_forum extends tx_forum_extended
 and not
 tx_forum_extended extends tx_forum


This is what I call reverse inheriting.



-- BUT --

Doing this would'nt be really efficient, as we would only be able to ADD 
methods to tx_forum, not to modify them
( because, as we're reverting inheritance, our custom methods would be 
overloaded by the classic ones in tx_forum, and that's not what we want )

-- THE SOLUTION ( maybe ? ) --

The solution would be this little trick :


 class tx_forum_old extends pi_base
 {
  function main()
  {}

  /* some code */
  /* this is the original method */
 }

 class tx_forum_extended extends tx_forum_old
 {
  /* our custom methods, overloading tx_forum */
 }

 class tx_forum extends tx_forum_extended  /* this is an empty, dummy class 
:) */
 {}       /* that is the trick */
        /* this presents to typo3 the modified tx_forum class with it's 
classic name */


This 'on-the-fly dynamic inheritance' has to be processed before inclusion 
by some weaver object ( yes, weaver, as in aspect oriented programing ;)

I already implemented such a weaver and succesfuly integrated it in TYPO3, 
packaged as an extension.
I tested it on typo3 extensions with 3 levels of inheritance ( instead of 
only one using XCLASS ) and it works great.

However my implementation of this idea is, for the moment, really trivial, 
and I'm posting this to get some feedback to know if it's worth the matter 
to go deeper in this direction.


Greetings, Jerome Schneider 






More information about the TYPO3-dev mailing list