File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes OO, Patterns, UML and Refactoring and the fly likes I need Design advice... 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 "I need Design advice..." Watch "I need Design advice..." New topic

I need Design advice...

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 751
Hi, I'm implementing a search module for my app. I was thinking if there is a good technique I could use for this.

if the user entered no search options( there are 3 options required like age preference, religion and citizenship). I was thinking of an implementation like this but it doesn't look elegant...

if (preferredAge.equals("") || religion.equals("") || citizenship.equals("") )
{, religion, citizenship)

that's making an overloaded version of search method. Any better ideas? Thanks!

SCJP 1.5
Orem Hun

Joined: May 24, 2005
Posts: 28
How about you encapsulate this into, religion, citizen).
If this is sql query:

String query = "select * from user_table where <default_conditions> " +
age.equals("")? "" : "age = ? " +
religion.equals("")? "" : "religion = ? " +
citizen.equals("")? "" : "citizen = ? " ;

By no means this is complete code, but should give you the idea.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Years ago I had a complex search screen in an environment that did not allow dynamic SQL. I made a "bitmap" of which fields were entered by the user:

if first-name is not null, set bit 1
if last-name is not null, set bit 2
if city is not null, set bit 4
if state is not null, set bit 8

and then made a mapping of bitmap values to prepared sql statements

I might resort to the same trick if the combinations of fields were really tricky.

But it's simpler to test for a few valid ones. Today we do dynamic SQL and test for minimum required inputs:

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: I need Design advice...
It's not a secret anymore!