Amitav Khandelwal
07/08/2021, 9:19 AMdata class
es, like Step1Output
, which becomes the input for step 2, and so on. I’ve managed to make the step functions are pure functions this way, which I believe is a best practice.
My problem now is that in case I need to introduce anything new in the output that requires another piece of data from the input, I need to modify all my StepXOutput
classes and keep passing on the data between them. This obviously makes doing any changes slow and painful.
Any ideas on design patterns that can help with this? Or is there some well-architected, complex project that I can look at for reference? Thanks!nfrankel
07/08/2021, 9:23 AMmight be more general software than kotlin/spring.it is general design hence... 😶
Amitav Khandelwal
07/08/2021, 9:25 AMkqr
07/08/2021, 10:44 AMAmitav Khandelwal
07/08/2021, 10:46 AMkqr
07/08/2021, 12:05 PMQuincy
07/08/2021, 12:56 PMdata class Step1Output(...)
you just passed around a Map<String, Any>
? You still need to deal with setting and accessing any new keys you put into the map later on, but nothing about how you transport the data needs to change. It's just a map.
If you have a need for a nested map, i.e., your existing data classes aren't just full of primitives, then you could wrap the map in a class the lets you more easily access the nested values.
For example:
outputMap.getValue("/firstKey/secondKey/thirdKey")
instead of
outputMap.get("firstKey")?.get("secondKey")?.get("thirdKey")
In projects I work on we've had a lot of success in the past using classes that delegate to a map as well.
data class Foo(map: Map<String, Any>): Map<String, Any> by map
You can add functions to Foo
to make certain patterns of data access easier, but you still get to treat it like a map. You can even add functions to set and retrieve values in a type safe way if that's important to you.nkiesel
07/08/2021, 4:15 PMAddressVerificationInput
/ AddressVerificationOutput
. This makes it much clearer what the data structures are use for, and if you e.g. break that step into "billing address" and "home address" steps, you only have to change this step.
Regarding using a map: we used that in our legacy system, and I hate it with passion: no type safety, refactoring is horribly complicated (esp. if developers get creative by creating "dynamic key computation functions"), and just try to find all the places where your "id" key/value pair is used.edrd
07/08/2021, 8:02 PMedrd
07/08/2021, 8:05 PMQuincy
07/09/2021, 1:42 PMDALDEI
10/03/2021, 3:02 AM