Reacting to things happening.
WHAT AN EVENT IS
A notification that something occurred.
WHAT A LISTENER IS
Code responding to it.
WHY USE THEM
So the code causing something does not need to know everything that should follow.
WHAT THAT ENABLES
Adding behaviour without modifying existing code.
EXAMPLES
A user registering, which triggers a welcome message and an internal notification An order being paid, which triggers fulfilment and a receipt
WHAT TO QUEUE
Listeners performing slow work.
WHAT TO BE CAREFUL WITH
Behaviour becoming hard to trace.
WHY
Reading the code that fires an event does not reveal what happens next.
WHAT TO DO ABOUT THAT
Document which listeners respond to each event.
WHEN NOT TO USE EVENTS
When the behaviour is essential and always required.
Call it directly, so it is visible.
WHAT MODEL EVENTS PROVIDE
Hooks at points in a record's life.
WHAT TO BE CAREFUL WITH
Model events not firing on bulk operations.