[TYPO3-dev] Hooks with interface
Ingo Renner
ingo at typo3.org
Mon Mar 2 11:26:29 CET 2009
Dmitry Dulepov wrote:
Hi Dmitry,
> Steffen Kamper wrote:
>> yes, something like that - latest RFCs with new hooks were all rejected
>> if they don't come with an interface.
>
> I do not remember that core team decided to support only interfaces for hooks.
just because you don't remember doesn't mean it isn't that way ;)
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.
all the best
Ingo
--
Ingo Renner
TYPO3 Core Developer, Release Manager TYPO3 4.2
More information about the TYPO3-dev
mailing list