Forums Register Login

Handling the criteria in a business layer

+Pie Number of slices to send: Send
I am working on the URLyBird assignment, and I make the criteria in a way I think it can be better, but I dont know how to do that improvment.
(Rinke makes me think about this after I read his topic about using string array or an VO...)

I have created a business layer, and an exclusive package for that. This layer is an adapter (adapter pattern) between the DBAccess interface to my new clean and easy to use business interface. The business interface is the one I am exposing via RMI to the clients.

And I have the following method in the business interface:

public ArrayList<Room> searchRoomsByCriteria(SearchCriteria criteria) throws IllegalArgumentException, BusinessFailureException;
Look at the parameter: I created an SearchCriteria (serializable class), just with the hotel name string and city location string (2 strings).
When the client wants to serach for the hotel name called "Palace", it need to create a SearchCriteria object, set the hotelName instance variable to "Palace", and call the method passing the object as the parameter.

Inside the method, I am creating an array of string with the fields of SearchCriteria (criteriaFields), and comparing with the just readed values from the database for a record (fields), as follow:



But my assignment talks about to create a flexible search mechanism. Is my implementation that flexible? I am not sure, I heard people talking about to use the strategy pattern in the criteria... I would appreciate some oppinions.

Thanks a lot,
+Pie Number of slices to send: Send
 

Originally posted by Marcelo Camargo:
But my assignment talks about to create a flexible search mechanism. Is my implementation that flexible? I am not sure, I heard people talking about to use the strategy pattern in the criteria... I would appreciate some oppinions.



Yes, I have been bothering about that too. The instructions seem to be a bit contradicting each other on that point.

First of all, the interface instructions tell you to create a flexible search mechanism, but the client needs only to search on two fields, and only wants exact matches, which is not at all my idea of a flexible search mechanism. So apparantly we are to create a flexible search mechanism in the DB package, but we don't need to use it ourselves in the client.

I choose the easy way out: my search mechanism for the db package is not so flexible because I explicitly only implemented that what was mentioned in the instructions, and nothing more. This means that it is not able to search on minimum or maximum values of numeric fields, but just interprets these fields as strings - which I think is highly inflexible, but alas.

It does return matches starting with the criteria String, and then the client filters these results to only return exact matches.
+Pie Number of slices to send: Send
Hi Rinke,

Exactly ! That's my thoughts. I did the same way as you, in the db access layer, any string field can be filtered (but only in string mode), using startsWith(). And, in the business layer, I filtered by the exact matches.

Another point is that I chose to make all searches case insensitive, and I documented it on the choices.txt, of course. Is that ok, do you have another opinion?

Thanks,
Marcelo.
+Pie Number of slices to send: Send
 

Originally posted by Marcelo Camargo:

Another point is that I chose to make all searches case insensitive, and I documented it on the choices.txt, of course. Is that ok, do you have another opinion?



I used case insensitivity, because I think case sensitivity makes no sense. But some people on this forum believe this is not according to the instructions, because instructions are talking about exact matches. So it depends on how exact you interpret the word exact
+Pie Number of slices to send: Send
 

Originally posted by rinke hoekstra:


I used case insensitivity, because I think case sensitivity makes no sense. But some people on this forum believe this is not according to the instructions, because instructions are talking about exact matches. So it depends on how exact you interpret the word exact



I think an interpretation of exact is not neccessary, the phrase contains the word must:

It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.



I suspect this may have something to do with automated testability of our programs. Hence, exact match cannot be implemented in the database, when the interface specifies otherwise (e.g. my URLyBird).
+Pie Number of slices to send: Send
hi!
I have done something different:
I was wondering about this problem for a long time and got this solution:
i implemented both "Exact Match Only" and "Starts whith Match" and left the deccision in the user's hands checking a checkbox.
-My implementation of "Exact Match Only" method uses a new method created in the data class. I didn't want to add methods not includen
in the DB interface but finally i did it without including it to the DB, of course. It performs the search better since it returns a list of contractors directly
whithout n-read calls.
-My implementation of "Starts whith Match" method uses the public int[] find(String[] criteria) of the Data class. Then i read the records returned.

I like your solution very much and think it adjust to the requirement, but finally i will decided to left my solution,
becouse i don't want the user to type an incomplete criteria and displaying no records.
You could also include the checkbox and implement the "Exact Match Only" method your way and include the "Starts whith Match" method.
Seems to be the best solution.
It's just a flesh wound! Or a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1085 times.
Similar Threads
Business Layer, Factory and and Business Layer Search method
URLyBird GUI MVC <-> Business Layer in a Thin Client and HashMap vs. ArrayList
Dedicated criteria object or String[]?
How to handle deleted records after find
String[] or VO??
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:20:56.