[TYPO3-core] Signals vs. Hooks

Philipp Gampe philipp.gampe at typo3.org
Mon Aug 25 18:38:07 CEST 2014


Hi Bernhard,

Bernhard Kraft wrote:

> Currently I didn't want to focus on the single/multiple aspect but
> ratheron the difference between observer and template pattern.

But this is important. Hooks do not make sense if only one subscriber can 
alter the data.

> How would you (or anyone else) describe the major differences between
> hooks and the signal/slots? Would you call both an observer?

Signal/Slots is something that comes from asynchronous data processing. It 
makes a lot of sense in many cases, but is actually only meant to inform 
someone that something has or will happen. The code informed cannot alter 
this any more.
The core violates this by allowing the slot to alter that data before it is 
passed to the next slot and finally to the caller again. This is a fair 
compromise, but smells a bit.

Hooks a lightweight approach to the traditional observer pattern. They allow 
you to register functions that called at certain steps of code with various 
variables passed on. They generally allow modification of the passed data or 
process the return value.
We lacking a consistent API and a central hook registry through.

There does not seem to be a really good way to implement hooks or any 
replacement of them ;) Otherwise someone would already have come across that 
holy grail.

Best regards
-- 
Philipp Gampe – PGP-Key 0AD96065 – TYPO3 UG Bonn/Köln
Documentation – Active contributor TYPO3 CMS
TYPO3 .... inspiring people to share!



More information about the TYPO3-team-core mailing list