Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我运行控制台应用程序时,我正在执行一系列步骤。假设步数为 8,它在第 4 步某处失败。
我希望能够恢复我在失败之前所做的第一步。如果它在任何步骤中失败,如何做到这一点?
如果您使用命令模式实现这些步骤,其中每个步骤都知道如何执行自身以及撤消自身。然后,您将能够遍历已完成的步骤并撤消它们。
您可能也对实现命令模式这个问题感兴趣。