File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Method Design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Method Design " Watch "Method Design " New topic
Author

Method Design

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Scenario-I

Is it a good practice to pass 5 parameters in a web application from one method to another to do null check and update the database from second method.








Scenario-II




In scenario-II null-check in done in the same method with if-else condition.

The problem here is there are 50 columns in the database that are to be updated. So with scenario-II there will be 50 if-else condition.

I feel scenario-I is not a good way of doing as we are call a method and passing 5 paramaters and updating the database there itself. There is no cohesion.

Scenario - II is also not good as we have 50 if-else statements.

Which one is better. Is there a better way of doing the same?


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
There are several issues with this code, which I think may be complicating the problem.

First, are you aware of preparedStatement.setObject() ? This seems designed to solve the kind of problem you are facing, and usually gets it right.

Second, I don't really understand why you are treating the Date parameter differently from other objects, and why it needs to be a separate parameter rather than being passed in objValue like all the other objects

Third, Are you aware that JDBC already includes convenient integer constants for all the parameter types it supports in java.sql.Types. Using those rather than making up your own could help make the code in your method clearer and simpler.

I don't really understand why you are using a default of NULL for integers, but a default of 0 for doubles - this might be a valuable part of your application, but it seems unusual. Using the same kind of default-value processing could well simplify your code.

Having said all that, in general I am in favour of your first approach over your second. Isolating a responsibility is almost always a good thing.

Why not take another look at your method and post a new version, and we'll see if we can make it even simpler.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method Design