s*********g 发帖数: 2350 | 1 For example, in a class there are ten variables each can change value by
later input. And when one variable is changed, the other nine variables is
also changed.
How to set up such that the changed value will not come back to change the
original one? Say, if 1st variable is input, 2nd variable is changed and 3nd
variable is changed. etc. But the 2nd variable will not try to change 1st
variable and 3rd variable will not try to change 2nd one, etc.
When there are few variables, this can be done by | h*****0 发帖数: 4889 | | s*********g 发帖数: 2350 | 3 不是。
var1 can be changed by input or var2;
var2 can be changed by input or var1.
要求是当var1 changed by var2; var1不会返回来再update var2.
如果变量很多, 怎么设置?
【在 h*****0 的大作中提到】 : 你的意思是不是:
| h*****0 发帖数: 4889 | 4 听不懂……
【在 s*********g 的大作中提到】 : 不是。 : var1 can be changed by input or var2; : var2 can be changed by input or var1. : 要求是当var1 changed by var2; var1不会返回来再update var2. : 如果变量很多, 怎么设置?
| w*****g 发帖数: 1415 | 5 如果variable之间是相互依赖的,他们最好不要同时是member,建议把variables之间的关系再抽
象一次。 | l*********s 发帖数: 5409 | 6 getter/setter to encapsulate your business logic away. | m******t 发帖数: 2416 | 7 I don't see any other way around it - you simply have to remember which
one triggered the chain, and use it as the "anchor".
3nd
【在 s*********g 的大作中提到】 : For example, in a class there are ten variables each can change value by : later input. And when one variable is changed, the other nine variables is : also changed. : How to set up such that the changed value will not come back to change the : original one? Say, if 1st variable is input, 2nd variable is changed and 3nd : variable is changed. etc. But the 2nd variable will not try to change 1st : variable and 3rd variable will not try to change 2nd one, etc. : When there are few variables, this can be done by
| g*****g 发帖数: 34805 | 8 Just use one level of indirection. e.g. have a class called Variable
class Variable {
boolean changed;
Object value;
public boolean setValue(Object value) {
if(changed) {
return false;
else {
this.value = value;
return true;
}
}
}
Then declare 10 instances.
3nd
【在 s*********g 的大作中提到】 : For example, in a class there are ten variables each can change value by : later input. And when one variable is changed, the other nine variables is : also changed. : How to set up such that the changed value will not come back to change the : original one? Say, if 1st variable is input, 2nd variable is changed and 3nd : variable is changed. etc. But the 2nd variable will not try to change 1st : variable and 3rd variable will not try to change 2nd one, etc. : When there are few variables, this can be done by
|
|