Mediator design pattern

Mediator design pattern

The mediator design pattern is a behavioral design pattern that promotes loose coupling among objects by centralizing communication between them.

It acts as an intermediary or mediator between objects allowing then to interact without having direct reference to one another.

How it works ?

When an object needs to communicate with another, instead of directly calling methods or properties of that object, it sends a request to the Mediator.

The Mediator, in turn, knows which object(s) should handle the request and forwards it accordingly. This helps reduce the dependencies between objects, making the system mor maintainable and flexible.

When to use the Mediator design pattern ?

The Mediator design pattern is used in scenarios where a system involves a large number of objects that need to collaborate or when the relationships between objects are complex. It can simplify the design and promote reusability of components.


要查看或添加评论,请登录

社区洞察

其他会员也浏览了