• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pass Lots of Parameters to Methods  RSS feed

 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have close to 30 parameters. I have to pass all those parameters to lots of the methods that are to be invoked. What is the proper way to do it? I am thinking to do the following and please comment.

1. create a Java Bean class called DefaultParameters. Declare all those 30 parameters with their respective type, and code getters and setters of those parameters in the Java Bean.

2. pass the DefaultParameters as one of the parameters in methods to be invoked:


3. retrieve each individual default parameter inside each method; for example:
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't a proper way to do it. It depends on the parameters.

If I had that problem I would start by asking things like whether the parameters come in groups, and various other analysis-type questions.
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . or consider whether it is a good idea to have a method requiring that many parameters in the first place. I read somewhere that somebody (probably Joshua Bloch) said you should never have more than three parameters for a method, because of the risk of confusion with more parameters.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Making Paul's point differently, a goal in Object Oriented programming should be to encapsulate a program's data as much as possible into objects and then create methods to operate on or with those objects to provide needed results. Can some, all, or a majority of those 30 parameters be included as parts of an object or split between a small number of objects?

Think about your design and how those parameters can be logically grouped into objects in a way that makes sense rather than considering each parameter as a separate entity that must have its own, top-level identity.

Good luck, and let us know what you work out.
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you for your help.

What I am assigned to do is the foremost front line of an application. After an application is launched, I am to get all of operational parameters; such as the application instance ID, application instance start time, measurements reset period, execution tracing logging level, application start date, etc. All of them will be made availabel for view via the Application admin GUI.

In additon, I have to instatiate all the major components of the application in sequence, and pass parameters; such as user request ID, request start time, parsed request URI, all aforementioned operational parameters, etc. to the methods of each of those major components of the application.

Question 1. I just found out that the operational parameters are in a XML file. Can we pass XML as a parameter to a method?
Question 2. What is the way to code this kind of very top level of an application? I have never done this kind of work before.


Thank you.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If everything is in an XML file, sure you can pass the DOM Document reference.

Personally, I do that sort of thing with a Map. That way you never get tangled up in the number of parameters because there is only the Map reference being passed.

Sure the store and retrieve using a key takes a tiny bit of extra time but if you choose the key words right it becomes nearly self documenting, well worth it in the long run.

Bill
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The major components in the application are; for example, Edit Logger Component, De-Duplicate Component, etc.

I have to invoke methods of every single major component in a sequential order.

Should I use thread? I mean if I should extends Thread and put method implementaion code in run()?
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I want to take back my question in regard to "thread".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!