实现“脏”标志功能的不同方式 [英] Different ways to implement 'dirty'-flag functionality
问题描述
- 在任何财产中
- 在特定的属性
- 或某些属性集
我是有兴趣在上述情况中实现脏标志功能的不同方式,除了在每个属性更改上更新的标准对象宽脏标志。在每个设置器中必须有一个比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
- in any property
- in a specific property
- 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屋!