Mediator Vs Observer Object-Oriented Design Patterns

前端 未结 8 772
一向
一向 2020-11-29 17:48

I have been reading the Gang Of Four, in order to solve some of my problems and came across the Mediator pattern.

I had earlier use

8条回答
  •  旧时难觅i
    2020-11-29 18:34

    How About this explanation Technically both Observer and Mediator are the same and are used to provide decoupled way for component communication, but usage is different.

    While obeserver notifies subscribed components about state changes (creation of new db record, for instance), the mediator commands registered components to do something related to business logic flow (sending email to user for password reset).

    Observer

    • Notification consumers are responsible to subscribe in order to receive notifications
    • Notification processing is not part of business flow

    Mediator

    • Explicit registration required to connect "publisher" and "consumers"
    • Notification processing is part of specific business flow

提交回复
热议问题