Answer the question
In order to leave comments, you need to log in
How to implement a large rollback using the command pattern?
I'll go straight to an example. There is an object (post, order, etc., it doesn’t matter) that has statuses (new, canceled, in processing, etc.) and when the status changes, dependent classes usually change (for example, if the status of the order is changed to paid, then there is a record of this event). And you need to implement a rollback of all this.
There is an example of a rollback on this site , but there is a nuance. Here there is a complete rollback to the previous state, and in my case, if history was made, I need to not delete it, but cancel it. + I need to return not just the number in the field, what it was, but to cancel what the execute command did .
There is another option to write undofor each command separately, but then a lot of the same code comes out (just in places with + it changes to -, etc.) since a change in the status in an object can bring changes in many classes and you can simply blunt and write the wrong undo for this all.
I don’t want to use crutches and I’m sure that there is a good solution that I haven’t come across yet, since the situation is not particularly unique. Thank you all in advance
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question