A
antoine
Hello,
I'm curious about the way I'm coding, as I actually believe I'm not
doing things correctly. I have a few general questions and even after
having read a few books and browsed the internet for some time, I can't
find the correct document describing the methodology I'm after...
I'm going to illustrate my questions through an example
I am building an application that computes prices of different
financial instruments. those instruments can be grouped in "groups"
with common "characteristics".
let's call my main class MAIN.
In it, I instanciate 2 objects SubLevel, that I call subLevel_1 and
subLevel_2
for each of those SubLevel Objects, I instanciate 10 Instruments
Objects (I put them in a Vector).
1. first question: the instruments need to "know" things (variable
values, Objects AND ints, doubles, etc...) that are described in their
SubLevel parent, and also in their MAIN parent. What is the correct
(best / cleanest) way to access those variables (parameters) ?
- should I pass all variables as parameters of my Constructor method ?
- should I pass a reference to the parent object, and then access those
values through accessor methods only ?
- when the variable I want to access is in the MAIN, should I consider
accessing it through something like:
int value = subLevelParent.getMAINParent().getMyValue(); ??
2. something else: if I pass variables in the constructor method,
should I pass the variable itself (int or double, etc...) or its Object
version (new Double(double)) ?
3. finally: I perform computation with a pretty long (lots of
parameters), but simple formula. I have a class that holds this
formula, but what is the best practice to call it ?
- should I create several instances of the class (each of which sharing
common specific values - one per "SubLevel" instance for example) and
access each instance when I want to compute ?
- or should I simply create a static class with a method taking this
long list of parameters and always use this class without instancing it
?
hmmm... I get the feeling that I should add a "WHEN..." in front of
those questions as there might be several answers possible depending on
the case...
it looks like newbie questions to me, but that's only today after
having developped in java for 4 years (alone...) that I feel the need
to solve that, so I'd be happy to get any insight, answer, book or
webpage recommendation for this
thanks for your valuable help...
Antoine
I'm curious about the way I'm coding, as I actually believe I'm not
doing things correctly. I have a few general questions and even after
having read a few books and browsed the internet for some time, I can't
find the correct document describing the methodology I'm after...
I'm going to illustrate my questions through an example
I am building an application that computes prices of different
financial instruments. those instruments can be grouped in "groups"
with common "characteristics".
let's call my main class MAIN.
In it, I instanciate 2 objects SubLevel, that I call subLevel_1 and
subLevel_2
for each of those SubLevel Objects, I instanciate 10 Instruments
Objects (I put them in a Vector).
1. first question: the instruments need to "know" things (variable
values, Objects AND ints, doubles, etc...) that are described in their
SubLevel parent, and also in their MAIN parent. What is the correct
(best / cleanest) way to access those variables (parameters) ?
- should I pass all variables as parameters of my Constructor method ?
- should I pass a reference to the parent object, and then access those
values through accessor methods only ?
- when the variable I want to access is in the MAIN, should I consider
accessing it through something like:
int value = subLevelParent.getMAINParent().getMyValue(); ??
2. something else: if I pass variables in the constructor method,
should I pass the variable itself (int or double, etc...) or its Object
version (new Double(double)) ?
3. finally: I perform computation with a pretty long (lots of
parameters), but simple formula. I have a class that holds this
formula, but what is the best practice to call it ?
- should I create several instances of the class (each of which sharing
common specific values - one per "SubLevel" instance for example) and
access each instance when I want to compute ?
- or should I simply create a static class with a method taking this
long list of parameters and always use this class without instancing it
?
hmmm... I get the feeling that I should add a "WHEN..." in front of
those questions as there might be several answers possible depending on
the case...
it looks like newbie questions to me, but that's only today after
having developped in java for 4 years (alone...) that I feel the need
to solve that, so I'd be happy to get any insight, answer, book or
webpage recommendation for this
thanks for your valuable help...
Antoine