| Author |
Strategy Pattern for Search Mechanism?
|
Ehsan Rahman
Ranch Hand
Joined: Feb 16, 2009
Posts: 59
|
|
Howdy All,
I suppose this question is all a matter of interpretation of the requirement: "a flexible search mechanism". My thinking is that filtering GUI side is fine, but in the future if a search algorithm is required such that a piece of text is to be searched across all data field values, then I think a strategy + command pattern would minimize client side changes, keep a single call to the server and also keep the 'searching business logic' in the business layer rather than at the GUI. However I fear these extra class will go to waste if I'm interpreting the world "flexible" wrongly. By flexibly does it mean just "Name or/and Location" searching or flexibility in terms of future maintenance of search algorithms?
Many Thanks,
Ehsan
|
SCJP 1.5, SCJD 1.6
|
 |
Roel De Nijs
Bartender
Joined: Jul 19, 2004
Posts: 4355
|
|
Hi Ehsan,
My search form has the ability to search for records on only name, only location, name and location or just return all records. My search form can be easily extended to add a search on date or size for example. No patterns used, just simple text fields which values are put in an array and send to the database to perform the search.
Although only just 2 fields are used to search on, my server is capable to search on every field (implementation was tested with a junit test case, just like all other methods from Data class).
Kind regards,
Roel
|
SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
|
 |
Ehsan Rahman
Ranch Hand
Joined: Feb 16, 2009
Posts: 59
|
|
Hi Roel, thank you.
It's definitely the more elegant approach. I suppose that if one wanted a search algorithm whereby they enter a piece of text and it searches throughout all data i.e. text, null, null, null, null, null; null, text, null, null, null, null; null, null, text, null, null, null .... null, null, null, null, null, text; then all 6 arrays can be called on the server. I'll state in my choices text this is sufficient for the task at hand and that the minor issues of maintenance and performance are outweighed by the more understandable approach.
|
 |
 |
|
|
subject: Strategy Pattern for Search Mechanism?
|
|
|