by asolove · 11y ago · 0 comments
The real question is: if our data has real validation and invariants, who maintains them?
- Does every piece of code that might change one attribute have to worry about it?
- Do individual objects protect themselves through methods and take responsibility?
- Or does a whole managed context take responsibility, allowing it to guarantee invariants about groups of objects together?
Experience tells us the first option quickly becomes problematic. The second certainly works, but requires discipline in how you design objects (the origin of many of the DDD patterns). The third is less widely used, seems to work better, but has some overhead. But don't kid yourself that it's less indirection/metaprogramming. It's more.
> we go through an even greater indirection, firing an abstract action and letting a store figure out how to make changes to the appropriate data
Can't this indirection just be modeled as a function? Instead of firing an action we call a function, which returns the appropriate state updates. No metaprogramming, and composable when used with cursor pattern to run the actual state update effect. (ActionStoreDispatcher flux doesn't compose)
(You probably know about this but others may not.) I like Elm's architecture, which has typed update functions that can be nested. This makes the full stack of the component composable and is something like a cursor: https://gist.github.com/evancz/2b2ba366cae1887fe621