Java – real world example of applying command patterns
•
Java
Command pattern can be used to implement transaction behavior (and undo)
Solution
In one of our projects, we have the following requirements:
>Create record in dB. > Call the service to update relevant records. > Call another service to log in the ticket
To execute in a transactional manner, each operation is implemented as a command with an undo operation At the end of each step, the command is pushed onto the stack If the operation fails at a certain step, we pop up the command from the stack and call the undo operation on each pop-up command The undo action for each step is defined in the command implementation to reverse the earlier command execute().
I hope this will help
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码