"撤销 "功能的最佳设计模式[英] Best design pattern for "undo" feature

本文是小编为大家收集整理的关于"撤销 "功能的最佳设计模式的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

可能的重复:
撤消引擎的设计模式

通常,您如何处理应用程序中的"撤消"功能?我曾在Web应用程序和桌面应用程序上工作,而且我从未真正对我制作的任何"撤消"系统感到满意.

推荐答案

我相信应该是命令设计模式.

这是文章关于多级undo/with命令模式.

编辑:这是第二关于Multilevel undo/with Memento模式.

因此,这可能两者都可以完成.

其他推荐答案

查看 Memento Pattern

其他推荐答案

我将投票支持命令模式而不是纪念品. Memento模式将比撤消/重做功能的命令模式要昂贵得多.

捕获和恢复对象状态 将是一件昂贵的事情 与仅做或撤消 对任何兼容对象的动作.

本文地址:https://www.itbaoku.cn/post/627562.html

问题描述

Possible Duplicate:
Design Pattern for Undo Engine

In general, how do you deal with supporting an "undo" feature in your application? I have worked on web apps and desktop apps alike, and I have never really felt comfortable with any "undo" system I've made.

推荐答案

I believe it should be Command design pattern.

Here is article about multilevel Undo/Redo with Command pattern.

EDIT: Here is second about multilevel Undo/Redo with Memento pattern.

So probably it can be done with both.

其他推荐答案

Check out the Memento Pattern

其他推荐答案

I'd vote in favor of Command pattern over Memento. Memento pattern would be much costlier then Command patterns for Undo/Redo functionality.

Capturing and Restoring object state will be quite an expensive affair compared to just doing or undoing an action on any compatible object.