With BrainSharper getting mature, the domain model is starting to show dependencies among the different objects. For example, a node can connect to other nodes, and before a node is deleted, all its connections need to be deleted.
The following ideas came to my mind:
Obviously, the second solution seems to be the only way to move forward.
Programming a solution to this specific problem is not a big task, but what about dependencies in general, what if they get more complex? For example, BrainSharper needs to support labels at the connectors and adding connections to the labels may also be allowed. And what if multiple nodes were deleted at once?
Consequently, there is a more generic, recursive dependency problem to solve. I guess this cries for a small DSL, which describes the dependencies among the domain model and specifies the events that need to be created to enforce the constraints.
Update: Instead of a DSL, I’ve implemented a dependency resolution algorithm which recognizes all destructive events in a change set and prefixes them with the destructive events of the dependent objects. The destructions had to be topologically sorted to remove duplicates and keep the order consistent. This ensures that the (re)creation events of the compensating change set were ordered properly. Not a perfect solution yet, but generic enough to be extended with a few lines of code.