Open koschos opened 1 year ago
Good points @koschos , thanks for the comment. 🙏
This implementation looks like a command pattern, not a mediator pattern Please, check this out in one of the most popular php implementations https://tactician.thephpleague.com/
It does have similarities with the command pattern, indeed. And it can also be a bit confusing since the term "generic mediator" is not very clear, and this particular implementation shares common characteristics with the command pattern in terms of encapsulating requests. And it indeed does match the "command bus" term, in your referenced link.
Technically though, it does not match the command pattern as per the strict definition of GoF(A command object encapsulates the invocation and can delay or queue a request’s execution and support undoable operations). At the same time, it does not match the definition of the mediator pattern either 😄. These are small technicalities related to "abstracting the interaction to promote isolation - Mediator pattern" vs "encapsulating all information within the command - Command Pattern" between sender and receiver.
I chose the term "generic mediator" since the mediation -abstracting the communication and isolating the participating colleagues- is the primary purpose of the main package of my implementation and it is also done in a generic manner that avoids the God object problem of the original mediator pattern. I've referenced this in the section "Wait, is this really a mediator pattern?"(https://pkritiotis.io/mediator-pattern-in-go/#wait-is-this-really-a-mediator-pattern-). This has actually been a discussion point in a very popular .NET library named MediaTR, and the author talks about it here(https://jimmybogard.com/you-probably-dont-need-to-worry-about-mediatr/).
Nonetheless, non-strictly speaking, we could consider this implementation as a command bus or maybe a combination of the mediator and the command pattern 😄. I guess the important thing from this implementation is the resulting benefit of loose coupling, reducing complicated dependencies, and promoting the separation of concerns.
The difference between the two is that Mediator knows about the types in advance, whereas Command tries to hide typing under some general (generic in languages where it is possible) types. That is why, I guess, the former is less popular as it is less extendable because adding new things requires changes in basic implementation.
Absolutely. The mediator
's primary focus is the interaction abstraction and isolation, not the command info encapsulation. They serve slightly different purposes and can be combined if needed.
Hi @pkritiotis
This implementation looks like a command pattern, not a mediator pattern Please, check this out in one of the most popular php implementations https://tactician.thephpleague.com/
The difference between the two is that
Mediator
knows about the types in advance, whereasCommand
tries to hide typing under some general (generic in languages where it is possible) types. That is why, I guess, the former is less popular as it is less extendable because adding new things requires changes in basic implementation.