Callback/Command vs EventListener/Observer Pattern

Command, callback and observer patterns have different semantics:

  • callback – notifies a single caller that some operation finished with some result
  • observer – notifies zero to n interested parties that some event (for example a finished operation) happened
  • command – encapsulates a operation call in an object thus making it transferable over a wire or persist-able

In your example you could combine both callback and observer patterns to achieve greater API flexibility:

  1. Use the callback pattern to trigger operations and notify the caller asynchronously that the triggered operation finished.
  2. Use the event/observer pattern to give some other components (that did not trigger the operation) the chance to be notified when an operation finishes.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)