Callbacks, callbacks everywhere
The callback functionality backs most Rails entities (controllers, models, channels, and so on). What is a callback? A callback is a piece of code executed when an operation is performed on the object. The execution of callbacks happens indirectly – that is, the operation only provides hooks but has zero knowledge of which callbacks are attached to it and their purposes.
Figure 4.1 – The execution of an operation with callbacks
Callbacks might remind you of the plugin-based architecture we discussed in Chapter 3, More Adapters, Less Implementations, but on a micro-scale (defined within a single Ruby class). Although there are similarities, there is a crucial difference between these two concepts – unlike plugins, callbacks don’t have to implement a particular interface, and they have no limits, neither technically nor conceptually. That makes them both powerful and dangerous.
Let’s see...