对象编辑和isDirty()标志 [英] object editing and isDirty() flag

查看:145
本文介绍了对象编辑和isDirty()标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用系统,用户可以通过GUI编辑现有对象(过滤域对象)。作为一个UI提示,我们只需要启用保存按钮,如果用户真的对对象进行了一些修改。我想知道有没有人有这个问题的经验,最好的方法是这样做。

I'm working on a system were a user can edit existing objects ("Filter" domain objects to be exact) through a GUI. As a UI hint, we only want to enable the save button if the user really modified something to the object. I was wondering if anyone had any experience with this problem and what the best way would be to approach this.

我在考虑在域中添加一个isDirty()标志目的。当用户开始编辑过滤器时,我将复制一份,将其传递给GUI,并让用户对该副本进行修改。然后,对isDirty()标志的绑定将启用/禁用保存按钮。在保存时,差异将被合并到原始对象中并持续存在。

I was thinking about adding an isDirty() flag to the domain object. When a user starts editing a Filter, I would then make a copy, pass it to the GUI and let the user make modifications to the copy. A binding on the isDirty() flag would then enabled/disable the save button. On saving, the differences would then be merged into the original object and persisted.

另外,我在想,如果用户将其对某个对象所做的更改。 isDirty()标志应该返回false。所以我想唯一的办法就是保持域对​​象中每个属性的原始值。

Additionaly, I was thinking what would happen if a user undos the changes he made to an object. The isDirty() flag should then return false. So I guess the only way to achieve this is to keep the original value of each property inside the domain object.

任何想法?

推荐答案

正确!

此外,您可以公开两种方法:
BeginEdit - 将您的IsDirty Flag标记为True。意思是你在做修改。调用此方法即将进行修改

Additionally,you can expose two methods: BeginEdit - In this method, your mark your IsDirty Flag to True. Meaning you are doing modification. Call this method when you are about to make modifications

CancelEdit - 在此方法中,将IsDirty标志重置为False。意思是你已经对编辑过程进行了修改,并恢复到原始状态。取消任何修改后,请调用此方法。

CancelEdit - In this method, reset the IsDirty Flag to False. Meaning you have arborted the edit process and reverted back to the original state. Call this method when cancelling any modifications made.

一旦任何修改都被保留,您也可以将IsDirty Flag重置为False。

And once any modifications are persisted, you also reset the IsDirty Flag to False.

我希望这有帮助。

这篇关于对象编辑和isDirty()标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆