Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command pattern #1

Open
koschos opened this issue Dec 27, 2022 · 1 comment
Open

Command pattern #1

koschos opened this issue Dec 27, 2022 · 1 comment

Comments

@koschos
Copy link

koschos commented Dec 27, 2022

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, 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.

@pkritiotis
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants