2

I built an app where the app owner can build custom forms for each of his clients. The forms have default fields like "name" and "message" as well as custom fields for each client requirement, like "whatsapp", which must trigger a switch in the app to send the message via Whatsapp instead of a Mailer.

So custom form fields are mapped to a use case.

I have used the Command Handler pattern before, so I was thinking that this might be a good use case for a Command Bus implementation. But I would hate to dive into this and find out that this is not what it's meant to be.

My approach would be to turn the custom form data into a command and pass it on to the Command Bus, possibly using the form field name for the command name itself. Any suggestions?

10
  • 1
    If I were doing it, I'd find a way to reflect over the form's controls and turn the data input into a JSON object. You can then take that JSON object and do whatever you want to with it: post it to a website, put it on a command bus, etc. Sep 11, 2018 at 17:37
  • What would be the benefit of turning the input data into JSON first - it is not passed to anywhere outside the app? Another thing that is confusing me right now: sending the form triggers an event from the framework - I would therefore attach a Command Bus to this single event, simply because this event is very likely to grow in complexity over time; I would think that CBs are meant to cover the commands of an entire app.
    – Hans
    Sep 11, 2018 at 17:47
  • The benefit of turning it into JSON is that it's a standardized format that can be read by a wide array of pre-existing software that doesn't have to know anything about your form or the technologies that is uses. This "design pattern" is called "Separation of Concerns." Your idea that a command bus might be used suggests that your application is larger than a single form, and the JSON reflector I suggested could be used on all of your forms, not just one. Sep 11, 2018 at 17:55
  • A Command Bus usually receives a command, not a JSON object, so I would have to turn this JSON object into a command first, the way I see it. While I think I get the benefits of JSON/XML data objects, I fail to see why I would profit from doing this with data that is not meant to circulate outside of the application scope. It feels like YAGNI, or creating an interface for a service or a controller, which is kind of a controversial question in itself.
    – Hans
    Sep 11, 2018 at 18:13
  • 1
    Well, you haven't told us much about the technologies you're using, the architecture you have chosen or the problems it all tries to solve, so its difficult to offer cogent advice. I don't think this is necessarily a software patterns problem per se. Normally, wouldn't command buses be used in larger projects? Sep 11, 2018 at 18:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.