[Tutor] General programming question
Kent Johnson
kent37 at tds.net
Tue Jul 18 14:42:03 CEST 2006
Tino Dai wrote:
> Hi Everybody,
>
> I have a general question about programming. My program that I
> have been writing is fully modularized. My question is: Is there a
> programming technique that would alleviate the passing of a huge
> number of variables. Let me further elucidate. I could see a day when
> I would be writing a several thousand line program that the variables
> that I would be passing into a object's method would be several lines
> long. In writing this email, I see two solutions. One is packing them
> into a list or a dictionary and then passing it up to the method.
You can also create a class to hold the variables and pass a class
instance to the method.
> The second I could see is passing variables into an ancestor and
> having that variable(s) propogate into the children, grandchildren,
> etc, etc so that you would be passing the set of variables once
> instead into the ancestor rather than to all the children.
I'm not sure what you mean by this, can you explain?
I guess you are using some classes but maybe your class design doesn't
fit the data. Try to find clusters of functions that act on the same
data and put those functions into a class. Ideally your classes will
each be responsible for a small, well-defined bit of the overall data
and functionality. Each class carries the data it needs to do its work.
Then instead of passing around a bunch of parameters you just pass a few
objects that encapsulate the data.
Kent
More information about the Tutor
mailing list