[TYPO3-dev] Hooks with interface

Franz Koch typo.removeformessage at fx-graefix.de
Mon Mar 2 12:47:53 CET 2009


Hi,

> Interfaces define a clear contract with the core - which userFunc 
> doesn't. You'll imidiately notice when not sticking to that contract.
> 
> Having that strict contract is a good thing:
> 
> * you know which methods to implement with which parameters
> * you'll notice if something is wrong
> * you'll notice if the interface changed
> 
> Now, attention to the third point: Using interfaces for the first time 
> allows us to actually modify hooks! Of course it will limit backwards 
> compatability in some way, but only in a very controlled and clear way.
> 
> If an extension uses a hook that requires the implementation of an 
> interfaces it does so by fullfilling the interface's contract. If we now 
> would change that contract the author would notice that, which is not 
> the case with hooks implemented through userFunc, is it?
> This results in another advantages for extension authors:
> 
> * they imidiately see what's the problem
> * they know how to solve the problem (by implementing the missing methods)
> * they can limit a certain version of an extension to a certain version 
> of the TYPO3 core
> 
> For the core this results in the following advantages:
> 
> * we can change hooks (!) (though we should be carful with it of course)
> * we do not have to worry about breaking something badly (as others will 
> notice and be notified about what to do by PHP)
> * changes in interfaces are easily traceable
> 
> 
> I hope that brought bake some memories why interfaces are so much better 
> for every one.

sorry for the probably stupid question, but how would registering a hook 
method look like in this case - will the registration be per file/class 
or would it then still be possible to register only for a certain hook 
out of 20 others in the same class?

If it would be per file/class - I wonder if it won't slow down rendering 
a bit if dozens of empty methods have to be checked then.
-- 
kind regards,
Franz Koch

---------------------------------------------------
PayPal-Account: 'paypal _at_ elements-net _dot_ de'
---------------------------------------------------




More information about the TYPO3-dev mailing list