由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - A design for parameter passing
相关主题
how do I get parameters passed by text area (formASP和java也不是互相排斥啊。
synchronized method does lock the object that passed into the method as a parameter?What do you think of XPath, XQuery, and XSLT?
【跪求】java applet下怎么执行系统的一个程序?how to insert a node in existing xml
how to make an html file in Eclipse?How to use "p = r.exec("simon parameters
parameters to main????copy constructor都什么时候be called啊
Re: how do I get parameters passed by teUrgent!
AJAX: simple question on parameter passingHow to make php and servlet work togethe
invoke a function dynamically in Java?weblogic 分布式问题
相关话题的讨论汇总
话题: parameter话题: main话题: passing话题: parameters话题: design
进入Java版参与讨论
1 (共1页)
g**********y
发帖数: 14569
1
Parameter passing between classes always bother me a lot. Noramlly, you take
parameters at Main class, then spread it to controls, then to different
modules/classes. A typical flow is like:
Main -> A -> B -> ... -> Z
Headache part is: At the beginning of design, you think B need param1 and
param2; then Main pass both to A, next B. Later, you find B actually needs
param1 and param3. Now you need to change all parameter passing sequence of
Main -> A, and A -> B. If the chain gets longer, it will b
g*****g
发帖数: 34805
2
It's like using a global hashtable to store all variables, I don't think
it's a good design.
Class A only needs parameters it needs to know, there's no point to
make parameter it doesn't need available in its scope.

【在 g**********y 的大作中提到】
: Parameter passing between classes always bother me a lot. Noramlly, you take
: parameters at Main class, then spread it to controls, then to different
: modules/classes. A typical flow is like:
: Main -> A -> B -> ... -> Z
: Headache part is: At the beginning of design, you think B need param1 and
: param2; then Main pass both to A, next B. Later, you find B actually needs
: param1 and param3. Now you need to change all parameter passing sequence of
: Main -> A, and A -> B. If the chain gets longer, it will b

g**********y
发帖数: 14569
3
Then what's your way to address the parameter passing hassle? Assumption is
that you will change passing parameter(s) between classes in future.

【在 g*****g 的大作中提到】
: It's like using a global hashtable to store all variables, I don't think
: it's a good design.
: Class A only needs parameters it needs to know, there's no point to
: make parameter it doesn't need available in its scope.

g*****g
发帖数: 34805
4
I think when the parameters get complicated, consider to pack the params
in a bean class and pass the bean.

【在 g**********y 的大作中提到】
: Then what's your way to address the parameter passing hassle? Assumption is
: that you will change passing parameter(s) between classes in future.

c*****t
发帖数: 1879
5
I think that for your problem:
1. Break them down into categories and have an object that represent
each category (and thus put attributes in that category only).
Then, you pass categories around.
Rarely you would create new categories of data, so, adding new
parameter only affect the data structure of categories object per se,
not any signatures of function calls. Thus saving you the refactoring
trouble.
2. Depending whether or not you clone the category object often, as well

【在 g**********y 的大作中提到】
: Parameter passing between classes always bother me a lot. Noramlly, you take
: parameters at Main class, then spread it to controls, then to different
: modules/classes. A typical flow is like:
: Main -> A -> B -> ... -> Z
: Headache part is: At the beginning of design, you think B need param1 and
: param2; then Main pass both to A, next B. Later, you find B actually needs
: param1 and param3. Now you need to change all parameter passing sequence of
: Main -> A, and A -> B. If the chain gets longer, it will b

g**********y
发帖数: 14569
6
Thanks for suggestion.
Creating category of data is a thought, just as DAO. But my problem is: I like
iterative model, quick modeling, prototype, further design, then more coding,
... During iterations, I change parameter passing. Normally, I only pass
minimum data as needed for object. Since our work is heavy data manipulation,
if I use DAO, there will be way too many classes cluttered in my design.
I do not worry too much about synchronization. It is single-thread, sequential
processing. I alr

【在 c*****t 的大作中提到】
: I think that for your problem:
: 1. Break them down into categories and have an object that represent
: each category (and thus put attributes in that category only).
: Then, you pass categories around.
: Rarely you would create new categories of data, so, adding new
: parameter only affect the data structure of categories object per se,
: not any signatures of function calls. Thus saving you the refactoring
: trouble.
: 2. Depending whether or not you clone the category object often, as well

b***g
发帖数: 6
7
I think most of such problems should be avoided by careful design. If you have
this problem again and again then you should make some better design practice
.
btw when this does happen, I just override a constructor or method, wouldn't
take long.

【在 g**********y 的大作中提到】
: Then what's your way to address the parameter passing hassle? Assumption is
: that you will change passing parameter(s) between classes in future.

c**g
发帖数: 274
8
1) use a refactoring tool.
2) could you share a real life example? Most cases you can design
such a way to avoid passing many parameters between differenct
classes, which is not a sound oo desgin in general.

【在 g**********y 的大作中提到】
: Parameter passing between classes always bother me a lot. Noramlly, you take
: parameters at Main class, then spread it to controls, then to different
: modules/classes. A typical flow is like:
: Main -> A -> B -> ... -> Z
: Headache part is: At the beginning of design, you think B need param1 and
: param2; then Main pass both to A, next B. Later, you find B actually needs
: param1 and param3. Now you need to change all parameter passing sequence of
: Main -> A, and A -> B. If the chain gets longer, it will b

m******t
发帖数: 2416
9

Why does Main have to find all the parameters for other classes?
If a parameter comes from command line, sure Main needs to process it,
but for everything else, such as configurations, each class/component
should deal with it itself.
If the API chain Main->A->B->C->... is so easy to be penetrated by
any parameter changes, I would first ask myself whether I have got
too many layers in the design, and maybe some of them are not doing
anything but passing through parameters.
parameters
what
be
aff

【在 g**********y 的大作中提到】
: Parameter passing between classes always bother me a lot. Noramlly, you take
: parameters at Main class, then spread it to controls, then to different
: modules/classes. A typical flow is like:
: Main -> A -> B -> ... -> Z
: Headache part is: At the beginning of design, you think B need param1 and
: param2; then Main pass both to A, next B. Later, you find B actually needs
: param1 and param3. Now you need to change all parameter passing sequence of
: Main -> A, and A -> B. If the chain gets longer, it will b

g*****g
发帖数: 34805
10
For example, in an applet, images are better loaded by applet at startup, so
that there's no delay when an animation needs it. Image is better passed from
applet to animation control when the control is created.
That being said, I don't see why parameters should be passed for many levels.

【在 m******t 的大作中提到】
:
: Why does Main have to find all the parameters for other classes?
: If a parameter comes from command line, sure Main needs to process it,
: but for everything else, such as configurations, each class/component
: should deal with it itself.
: If the API chain Main->A->B->C->... is so easy to be penetrated by
: any parameter changes, I would first ask myself whether I have got
: too many layers in the design, and maybe some of them are not doing
: anything but passing through parameters.
: parameters

相关主题
Re: how do I get parameters passed by teASP和java也不是互相排斥啊。
AJAX: simple question on parameter passingWhat do you think of XPath, XQuery, and XSLT?
invoke a function dynamically in Java?how to insert a node in existing xml
进入Java版参与讨论
m******t
发帖数: 2416
11

from
The images are better loaded at startup doesn't mean they have to be loaded
by the applet class (or any name we might call the "main" class). The applet
class could let the image control participate
in the initialization - the concerns of how to load the images are of the
image
control's not the applet class'. In other words, the applet class only pays
attention to the general initialization sequence, but not necessarily every
detail of it.

【在 g*****g 的大作中提到】
: For example, in an applet, images are better loaded by applet at startup, so
: that there's no delay when an animation needs it. Image is better passed from
: applet to animation control when the control is created.
: That being said, I don't see why parameters should be passed for many levels.

g*****g
发帖数: 34805
12
If you initialize every control in the very beginning, sure, you can let the
control load the images, however, if the control is supposed to be created
dynamically, such as different animation under different condition.
It's not possible to let a non-exist control to load the image. Instead,
use an image warehouse in applet and pass images to control when they
are created seem to be more efficient for me.

【在 m******t 的大作中提到】
:
: from
: The images are better loaded at startup doesn't mean they have to be loaded
: by the applet class (or any name we might call the "main" class). The applet
: class could let the image control participate
: in the initialization - the concerns of how to load the images are of the
: image
: control's not the applet class'. In other words, the applet class only pays
: attention to the general initialization sequence, but not necessarily every
: detail of it.

m******t
发帖数: 2416
13

That's perfectly fine. Create a separate "ImageWarehouse" to contain the image
management (including loading) logic then. Just don't mix it in the main
class
itself. That's all I'm saying in relevance to the OP.

【在 g*****g 的大作中提到】
: If you initialize every control in the very beginning, sure, you can let the
: control load the images, however, if the control is supposed to be created
: dynamically, such as different animation under different condition.
: It's not possible to let a non-exist control to load the image. Instead,
: use an image warehouse in applet and pass images to control when they
: are created seem to be more efficient for me.

g**********y
发帖数: 14569
14
This is the project I am doing now --
I need to convert XML files version 1 to version 2. Files are stored in tree-
structure like unix-directory, and the rules are:
* some file in version 1 will be split into multiple ones of version 2
* other files will be structural changes
* Almost every file has its own special rule, and I cannot extract a general
one
* If files in one sub-directory, they use same rule.
- And structure changes can be drastic, DONT even think about using XSLT!
- A typical XM

【在 c**g 的大作中提到】
: 1) use a refactoring tool.
: 2) could you share a real life example? Most cases you can design
: such a way to avoid passing many parameters between differenct
: classes, which is not a sound oo desgin in general.

m******t
发帖数: 2416
15

I don't see anything terribly wrong in this. If the parameters are constantly
changing, maybe consider a hierarchy of parameter bean classes (as somebody
else suggested earlier), so that you don't have to keep changing method
signatures.
Another alternative would be to make the Rule classes themselves parameter
beans. The Converter would inject parameters into a Rule bean prior to calling
its conversion method, instead of passing them as parameters. If most XML
files are large files, conversio

【在 g**********y 的大作中提到】
: This is the project I am doing now --
: I need to convert XML files version 1 to version 2. Files are stored in tree-
: structure like unix-directory, and the rules are:
: * some file in version 1 will be split into multiple ones of version 2
: * other files will be structural changes
: * Almost every file has its own special rule, and I cannot extract a general
: one
: * If files in one sub-directory, they use same rule.
: - And structure changes can be drastic, DONT even think about using XSLT!
: - A typical XM

c**g
发帖数: 274
16
What are exactly these "parameters"? to me, it looks like you have
three separate parts:
1) a spider like class, which goes through a directory.
2) a convertor, which is in charge of reading/wrting xml file,
parse/syntactic analysis xml file.
3) rules.
As i can see, the only parameter necessary to be passed from 1) -> 2) -3)
is pathname/File reference.
Just curious, what are these 15-20M xml used for? I heard people
used xml to replace database, but have never had a chance to see
a real case. :-

【在 g**********y 的大作中提到】
: This is the project I am doing now --
: I need to convert XML files version 1 to version 2. Files are stored in tree-
: structure like unix-directory, and the rules are:
: * some file in version 1 will be split into multiple ones of version 2
: * other files will be structural changes
: * Almost every file has its own special rule, and I cannot extract a general
: one
: * If files in one sub-directory, they use same rule.
: - And structure changes can be drastic, DONT even think about using XSLT!
: - A typical XM

g**********y
发帖数: 14569
17
File/directory path are most parameters, but not all. Some XML nodes need to
be passed among these class -- our XML structure is so wild, the change can be
ANYTHING, ANYWAY :-) totally up to programmer's taste.
15-20M xml are used for defining business data structure, database connection
mapping, our software specific data, also a lot of user-defined javascripts,
etc. When programming in financial business, you will know that amount is not
uncommon. There are just way too many variations, busine

【在 c**g 的大作中提到】
: What are exactly these "parameters"? to me, it looks like you have
: three separate parts:
: 1) a spider like class, which goes through a directory.
: 2) a convertor, which is in charge of reading/wrting xml file,
: parse/syntactic analysis xml file.
: 3) rules.
: As i can see, the only parameter necessary to be passed from 1) -> 2) -3)
: is pathname/File reference.
: Just curious, what are these 15-20M xml used for? I heard people
: used xml to replace database, but have never had a chance to see

1 (共1页)
进入Java版参与讨论
相关主题
weblogic 分布式问题parameters to main????
help: 如何用servlet实现zip文件下载?Re: how do I get parameters passed by te
Suggestion Re: 发现 synchronized 的一个问题AJAX: simple question on parameter passing
今天面试。invoke a function dynamically in Java?
how do I get parameters passed by text area (formASP和java也不是互相排斥啊。
synchronized method does lock the object that passed into the method as a parameter?What do you think of XPath, XQuery, and XSLT?
【跪求】java applet下怎么执行系统的一个程序?how to insert a node in existing xml
how to make an html file in Eclipse?How to use "p = r.exec("simon parameters
相关话题的讨论汇总
话题: parameter话题: main话题: passing话题: parameters话题: design