Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mediator pattern or too much responsibility

In my application, I have several components that have to know about each other, such as a menu bar and a tool bar that both need to know about the table to add or remove jobs and also to find out which job is selected.

So, I created a object called guiMediator that I pass to every object and they register themselves with it so that they can reach each other using that object. It is also responsible to fire events when new jobs are added or background workers finish their job.

Since it knows a lot about the system, is this type of usage too much responsibility in one place, or is this the correct usage of the pattern?

like image 625
Hamza Yerlikaya Avatar asked Feb 26 '26 05:02

Hamza Yerlikaya


1 Answers

Normally I would use the command pattern for something like that:

  1. User clicks the "Foo" button on menu bar, which executes the FooButtonClickedCommand.
  2. FooButtonClickedCommand does whatever it's supposed to do, then modifies the view (menu bar, tables, etc) appropriately.

So your commands know about all your view components, but the only thing your view components need to know is which command to execute when a given action is done by the user.

like image 200
Eric Petroelje Avatar answered Mar 01 '26 19:03

Eric Petroelje



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!