0

Imagine while using the command pattern, I have a quite a few different commands (> 30), now most of them are very similar but they depend upon an answer after execution (think in a dinner example, as the waiter needing feedback from the guest, whether they received the right meal).

Now basically I could reduce the numbers of commands and receivers drastically by outsourcing the business logic associated to the answer to an external object, that the client sets on command creation and which will be forwarded the answer, the receiver is getting. (sorry for that sentence)

Now would this make sense, or should I rather create a different receiver and command for each type of of command and pack the business logic, concerned with the generated response, inside them.

I think kind of both do makes sense to some degree, because in essence those commands are actually different things and treating them the same is merely an abstraction. But it would couple the "answering logic" to the command and/or its receiver, as well as pollute the application with many mostly similar classes.

What would be the most elegant way (if something like this exists), to go about this?

2

You should choose the solution that results in the simplest, smallest amount of code. This is probably the design you had in mind, though its expression in your question is not entirely clear. You should choose the simplest solution for your specific requirements, regardless of any general purpose design recommendations you receive.

All too often, the questions in the software engineering platform are asking for generic solutions to specific problems, rather than specific solutions to specific problems. The simplest solution will always be specific to the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.