由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - how to solve the problem: the members change by each other .
相关主题
JavaBean variable name standardSuggestion Re: 发现 synchronized 的一个问题
问一个java的面试题 (转载)java里面怎么得到一个系统的环境变量?
Windows2000中CLASSPATH怎么设?Java大侠们:Hashtable help please!
get System environment variable帮忙看看. Get context variable
interface可不可以有variable?SYSDEO tomcat的问题。
java 程序中的实时控制a question
help on this scope questionstart up tomcat problem
Re: java里怎么判断一个文件存在不存在?new thread object 占的是heap还是stack?
相关话题的讨论汇总
话题: variable话题: changed话题: change话题: variables话题: other
进入Java版参与讨论
1 (共1页)
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
2
你的意思是不是:
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

1 (共1页)
进入Java版参与讨论
相关主题
new thread object 占的是heap还是stack?interface可不可以有variable?
anyone saw this on code?java 程序中的实时控制
get sethelp on this scope question
新手问题 -- dynamic variable and dynamic functions.Re: java里怎么判断一个文件存在不存在?
JavaBean variable name standardSuggestion Re: 发现 synchronized 的一个问题
问一个java的面试题 (转载)java里面怎么得到一个系统的环境变量?
Windows2000中CLASSPATH怎么设?Java大侠们:Hashtable help please!
get System environment variable帮忙看看. Get context variable
相关话题的讨论汇总
话题: variable话题: changed话题: change话题: variables话题: other