We have a set of domain objects that can be edited through in one window and used at the same time in other window. To ensure that the objects are in a valid state at all times and that changes are not visible to the outside world until they are committed. The objects are stored in a repository (each object has an unique id).
- User opens "Run" - window (read-only access to object A)
- User opens "Edit"-window (read/write access to object A)
- User changes some properties in the UI, but does not click apply
- User clicks the "Run"-button in the Run-window. The Run-operation should be performed with the "old" settings.
- User clicks the "Apply"-button in the Edit-window and Run in the Run-window. The Run-operation is performed with the "new" settings.
I can think of a few solutions, but I'm not very happy with either of them:
- When checking out objects from the repository, a clone is always returned. If one wish to store changes, the object must be explicitly committed to the repository. This could work well for small objects, but in cases where the object model is big it might not be plausible to clone everything.
- The view model or model stores intermediate changes and does not change the underlying domain object until the user decides that the changes should be applied. This sounds a bit tedious and will require a lot of validation rules in the view-models that we would rather like to have in the domain objects.
- The UI does not work directly on domain objects. Rather, they change DTOs that can be applied to the domain objects when the user applies the changes.
Note that there only will be one concurrent editor, but there might be multiple concurrent "readers". Also, concurrency won't be an issue (in the sense partially updated objects in a multi-threaded environment).
How can we implement a pattern for editing domain objects without applying changes until the changes are committed? Are there any frameworks I should look into?