【计算机英语】Another approach is to simply not set the property until you've finished with the...

来源:百度知道 编辑:UC知道 时间:2024/06/06 01:47:10
Another approach is to simply not set the property until you've finished with the change. Let's see if I can come up with another example. Assume that there are two fields, and either both field have to be set or neither of them. Again, a method would solve the problem, but if you scale up this problem or consider that the UI would prefer to have the properties exposed with setters, it's clear that it's hard not to get into an inconsistent state there from time to time.

另一个简单的方法是,知道修改完成才设置属性。
我能想到一个例子。假设有两个Field,必须同时设置或者不设置。
在次。利用一个method 可以解决这个问题。
但是假如你放大这个问题或者认为UI持有这个属性并exposed给设置者。
很明显。有事很难不进入一个无效状态。

-----------------
我翻译的有问题么?

为什么【很明显。有事很难不进入一个无效状态。】?
我根本看不出来前面的描述为什么产生了这个原因!

请高手指点!

我觉得是这句but if you scale up this problem or consider that the UI would prefer to have the properties exposed with setters。这句可以解释为如果你把这个问题夸大,认为用户接口需要用set函数去设置这些属性。

我的总体理解是:两个field必须同时被设置或者不设置,你只要提供一个接口method,在这个method里去完成这对这两个field的操作就可以了。但如果你对外提供set方法(当然是每个field一个set),则有可能用户只set了一个field,这就违背了两个field必须同进退的原则。

感觉像面向对象方面的。