• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class Design Advice For Objects With Many Data Points  RSS feed

 
Steve Math
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to Java and most of my class design experience has been limited to the classroom. I'd like some advice on designing a class(es).

I'm working with data that consists of measurements from RF signals. Each instance has around 45 data points of several different types. Shoving 45 pieces of data into a single class looks like a bad idea. I've seen posts (on other sites) where it was suggested that large amounts of data be stored in something like an array or hashtable in a class. I'm thinking a better solution would be to split the related elements of each instance into their own classes and then make a container for those classes and any remaining pieces of data. Am I on the right track or is there a better way to handle objects that have a lot data points?
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is just my opinion, but I see no problem in and of itself with 45 instance variables, if the logic of your program suggests that, and if the code is easy enough to read. 45 doesn't seem particularly large, and some of your alternatives to me seem unnecessarily complicated.

If it is a situation where there are some types of instance variables that are common to all instances, and other types of variables that are only typical of some instances, you may wish to consider some type of subclassing of your objects.

for more information on subclassing, go here...

http://java.sun.com/docs/books/tutorial/java/IandI/subclasses.html

some of the more experienced guys may have something else to say about this, I don't know.
 
Steve Math
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Fred. I'll press forward with a single class.

Steve
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch I presume you can write down on a piece of paper that there is an entity which has 45 variables, and its description.

If you can subdivide it, probably a good idea to do so. Don't know what you have, but imagine a carNow, it should be quite easy to have an Engine field and the fuel CC horsepower and cylinders become fields of the Engine. You have Lamps with on/off incorporated, etc.

Divide and Rule, or "favour composition over inheritance".
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
agreed, in the car example, the types of variables being tracked do lend themselves to a breakdown, for clarity and organization if not performance, and inheritance does not seem appropriate.

But if we are categorizing the type of car, and our objects are themselves cars, where each type of car might have a different number of doors, or a different number of cyclinders, then subclassing might be appropriate for that. It depends on what differentiates the categories.

regards.

 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only tell if you write down all the different variables and their relationships to one another. A "composition" pattern might then appear.
 
Steve Math
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would be the original class:


This seems (to me) awkward. I was thinking I could group some of the data points into their own classes and reduce it to:


I think that is a better approach, but now I have six classes instead of one.

Thanks,
Steve
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As soon as I saw receiverLat and receiverLong, I thought you need a Receiver class which incorporates those location data, so I would agree that 6 classes are better.
 
Steve Math
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I suppose it depends on what you're trying to model.

Thanks for the advice!
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!