This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes A little help defining my objects? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A little help defining my objects?" Watch "A little help defining my objects?" New topic
Author

A little help defining my objects?

Jon Swanson
Ranch Hand

Joined: Oct 10, 2011
Posts: 200
I have the need to build a table with 7 columns. I'll just call them

A B C D d e f

D is a measured value, measured under the conditions (A, B, C).

So I plan to define a dataPoint class that can get/set that information.

d, e, and f are computed. If they were just computed from (A,B,C,D) directly, I think I would just have another
class of dataPoint objects and methods to calculate the values.

It is not quite that simple, d is calculated on each subset of datapoints that have the same (A.B,C). That then
creates a new set of data A B C D' d (the mean of D replaces D). In the table I need to enter the same d for
each of the values of D that make up D'.

From that modified data, A B C D' d, values of e and f are calculated for each subset of datapoints that have
the same (A,B).

So I might have


1 2 1 4
1 2 1 4.5
1 2 2 5
1 2 3 6
2 2 1 4
2 2 2 5

that becomes

1 2 1 4.25 0.25
1 2 2 5 0.5
1 2 3 6 0.6
2 2 2 4 0.4
2 2 2 5 0.4

which becomes

1 2 - - - 5.1 0.3
2 2 - - - 4.4 0.2

which is then used in a follow-on calculation.

The table needs to show

1 2 1 4 0.25 5.1 0.3
1 2 1 4.5 0.25 5.1 0.3
1 2 2 5 0.5 5.1 0.3
1 2 3 6 0.6 5.1 0.3
2 2 1 4 0.4 4.4 0.2
2 2 2 5 0.4 4.4 0.2

in the current requirement, though I suspect that will be changed so the derived values only show up once.

Should I make all these intermediate tables have their own classes or should I just hide them under one class that has a get/set for the
user entered data and methods to make the intermediates hidden from the user and methods to return the two types of data (the one for
the visible table and the one for the data that will be used in the next step).

Also, I was thinking in terms of lists of objects (like a list of data points), thus my thinking I'd have multiple objects, one for each step as
the data was modified from original input to final result. Is this even the right way to think about this?

Since I am going to have a table in a GUI, do all these operations sit inside my tableModel code?




Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8048
    
  22

Jon Swanson wrote:Should I make all these intermediate tables have their own classes or should I just hide them under one class that has a get/set for the
user entered data and methods to make the intermediates hidden from the user and methods to return the two types of data (the one for
the visible table and the one for the data that will be used in the next step).

From what I've read, yes; but I wouldn't think of them as tables; I'd think of them as objects (or classes). What are they? What do they represent? Clearly you have an idea; otherwise, you wouldn't be asking the question. And therefore you are the best person to name them - and it's the name, I suspect, that will lead you to the structure.

Also, I was thinking in terms of lists of objects (like a list of data points), thus my thinking I'd have multiple objects, one for each step as
the data was modified from original input to final result. Is this even the right way to think about this?

Absolutely. But get the first bit right; I suspect (a lot of 'suspects' here, you notice) that when you get that right, the rest will probably fall into place.

You might want to pop back before you make your final choice for your collection of objects though; Java provides a dizzying array of them, and the folks here may be able to point you to the best one for the task.

Since I am going to have a table in a GUI, do all these operations sit inside my tableModel code?

I'm no GUI expert, but my advice: get the rest of it right first and then worry about how it fits in your GUI. An engine isn't rubbish simply because the mount points aren't quite right.

Winston





Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18712
    
    8

Winston Gutkowski wrote:... a lot of things...


... to which I would just reiterate: you're considering the GUI more than is healthy for a data design, in particular I think the idea that you're going to be displaying the data as a table may be impairing your judgement.
Jon Swanson
Ranch Hand

Joined: Oct 10, 2011
Posts: 200
So far my GUI dialogs have only had text fields. So the dialog was nothing more than a data gatherer. I would scoop up the information and store it in an object when the user clicked OK. If I need to display data, I would populate the display as a single event based on the object.

I'm pretty good at over-thinking problems. This is the first time I am using a table and the same table is used for data entry and display. The number of rows can also change dynamically. The table has an object that it maintains that keeps track of what is in the table. My confusion is that if I have my own independent objects, the data is now in two places and I have to keep them in synch. That seems like a bad idea. So I'm not trying to obsess over the GUI, but it seems like if I can build a TableModel that manages to do all the manipulations I need and then create the table using that table model, then I don't have to worry about keeping the data consistent. So I was thinking of playing around a bit to try and understand what happens after I pass my Object data[][] into the default table model, that is, can I use it directly and will the table view reflect changes in it without going nuts.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A little help defining my objects?