Callback
Callbacks are a convenient way to decorate the default save method with cus- tom persistence logic, without the drudgery of template methods, overriding, or calling super.
However, callbacks are frequently abused by adding non-persistence logic to the persistence life cycle, such as sending emails or processing payments. Models riddled with callbacks are harder to refactor and prone to bugs, such as accidentally sending emails or performing external changes before a database transaction is committed.
Symptoms
• Callbacks which contain business logic such as processing payments.
• Attributes which allow certain callbacks to be skipped.
• Methods such as save_without_sending_email
which skip callbacks.
• Callbacks which need to be invoked conditionally.
Solutions
- Replace Callback with Method if the callback logic is unrelated to persistence.