I have a struts and hibernate project,
-
From the action class, I need to call the DAO, to get the data from the database.
-
I need all the fields in the form class, to be passed to method in the DAO.
The form has about 15 fields, all are of type String.
Which is better or efficient: Pass the fields directly to the DAO, or the entire FORM object as a parameter?
Imagine a method with 15 String parameters:
Oh look, a horizontal scrollbar. And a pretty small button. Hm. That looks dubious. Don’t do it.
It’s always better to collect parameters in a parameter object if you have more than 3 or 4 of them. Long parameter lists create the following problems:
You can’t omit any paramater. So if you don’t need any of them, you’ll have to pass lots of
nulls or something.The order of parameters is fixed. If you need to change it, or add parameters, you’re always in trouble. If you make a mistake (and you will), there is no easy way to find out where.
If you use a parameter object with setters and getters, you can fill in the values in any order.
Parameters have no name. Example:
what does that mean? Look here:
Oh, it’s a phone number. Now it’s obvious.