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

查看:18
本文介绍了对象编辑和 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 标志标记为 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 标志重置为 False.

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

我希望这会有所帮助.

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

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