We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Objects OOP and reading & passing data
Page Index Toggle Pages: 1
Objects OOP and reading & passing data (Read 274 times)
Objects OOP and reading & passing data
Sep 27th, 2008, 2:05pm
 
Im about to rewrite one of my programms as i gained abit more programmings skills and i can tell it was really bad code :)
Anyway before i start i got a question to make it the right way from the beginning.

Lets say the programm is reading data out of a textfile and creates different objects out of this data. for example, different sized ellipses and the size is written in the textfile.

So my question is,when is the right time to read and pass the data to the object? I used two different ways, but i can tell non of them is a good one i guess...

So first i red the data when creating the spots like this :

for(int i = 1; i<spots.length; i++){
float size = dataTable.getFloat(i);
spots[i] = new Spot(size);
}

the other attemp was just passing the number of the object

for(int i = 1; i<spots.length; i++){
spots[i] = new Spot(i);
}

and then reading the data at the object setup

... Spot(int number){
int _number = number;
float size = dataTable.getFloat(_number);
}...

or is there any other way to do this,
and i was asking myself if i can skip the "passing i" part and just read which instance of the object it is to get the right data out of the file...


Thanks!


Re: Objects OOP and reading & passing data
Reply #1 - Sep 28th, 2008, 11:35pm
 
I would use the #1 way. Passing a property (the size) instead of a meaningless number (which turns out to be a pointer) seems more natural to me (and more reusable).
Re: Objects OOP and reading & passing data
Reply #2 - Sep 28th, 2008, 11:45pm
 
Thanks, thats the one i have chosen. I thought there is maybe another way, but i asked 2 more people and they both also told me to go with the first one...
Page Index Toggle Pages: 1