实现“脏”标志功能的不同方式 [英] Different ways to implement 'dirty'-flag functionality

查看:107
本文介绍了实现“脏”标志功能的不同方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几乎每个程序员都在他的生活中做了一次:如果一个变量的值改变,设置一些标志。总有很多财产,如果有变化,您希望跟踪


  1. 在任何财产中

  2. 在特定的属性

  3. 或某些属性集

我是有兴趣在上述情况中实现脏标志功能的不同方式,除了在每个属性更改上更新的标准对象宽脏标志。在每个设置器中必须有一个比dirty = true更好的东西:它看起来很丑陋,是一件乏味的工作。

解决方案

对于我的DAO,我保留从数据库检索的原始值的副本。当我发送它进行更新时,我只是将原始值与当前值进行比较。它在处理上花了一点钱,但是比每个属性都有一个脏标志好多了。



编辑进一步证明没有脏标记:如果属性返回它的原始价值,没有办法反映,肮脏的旗帜继续肮脏,因为原始的价值损失。


Almost every programmer did it once in his life: setting some flag if a variable's value changed. There's always lots of properties and you want to keep track if something changed

  1. in any property
  2. in a specific property
  3. or in some set of properties

I'm interested in different ways to implement the "dirty-flag" functionality for the above situations, besides the standard object wide dirty flag being updated on each property change. There must be something better than putting "dirty = true" in each setter: it just looks ugly and is a tedious work.

解决方案

For my DAO I keep a copy of the original values as retrieved from the database. When I send it to be updated, I simply compare the original values with the current. It costs a little in processing but it is a lot better than having a dirty flag per property.

EDIT to further justify not having a dirty flag: if the property returns to its original value, there is no way to reflect that, the dirty flag continues dirty because the original value was lost.

这篇关于实现“脏”标志功能的不同方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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