Mediator Vs Observer Object-Oriented Design Patterns

前端 未结 8 737
一向
一向 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条回答
  •  遥遥无期
    2020-11-29 18:27

    These patterns are used in different situations:

    The mediator pattern is used when you have two sub-systems with some dependency and one of them is due for a change, and since you might not want to change the system that depends on the other, you may want to introduce a mediator which will decouple the dependency between them. That way, when one of the sub-systems changes, all you have to do is to update the mediator.

    The observer pattern is used when a class wants to allow other classes to register themselves and receive notifications upon events, e. g. ButtonListener etc.

    Both of these patterns allow for lesser coupling, but are quite different.

提交回复
热议问题