4 ms·
The command design pattern never ceases to amaze me. Package up a complicated process in an "input, process, output" package. Turn it into a black box. The inpu
by JohnDeHope 4y ago
The command design pattern never ceases to amaze me. Package up a complicated process in an "input, process, output" package. Turn it into a black box. The input should be as small as possible, just the details and data you need to "do the needful". The output should be as little as possible to explain how things went. I usually let my code grow organically, but once it gets to a certain point, using this technique really helps clean things up.
- rjh29 4y agoIsn't that just a function?
- JohnDeHope 4y agoYes. There's some nuance to it, but at the end of the day, yes it is just a function call. Usually the input and output are complex types which express the desired behavior or parameters of the process. There's some conceptual distance between a function that takes two integers and returns an integer, and one that takes a complex series of mutually related arguments, some possible business objects with child objects attached, etc.