Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: Search Criteria + DAO's

 
Mickey Mulligan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just curious - how did people model the search criteria as an object?

I've decided not pass a String Array directly to the server and to specify a SearchCriteria transfer object instead, deal with this at the business layer on the server and pass the resulting Record list back to the GUI.



So I would have each of the fields specified in recordToFind and also booleans specifying the logic (AND/OR) and match type to use (partial/exact).

But how would I represent a wildcard in such an object, while allowing the fields in Record to be strongly typed? (an int can't be null, for example)

In the recordToFind object above, "name" is a String, "size" is an int, "rate" is a float and so on.

I suppose I could use wrapper objects ("rate" as Float, "size" as Integer and so on). These wrapper objects can be set to null to match any value.

Has anyone any tips for this?

Thanks!
 
Dalton Filho
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are in the right direction by encapsulating the search criteria into a class of its own, but I'm not too confortable with your design for this class.

If you have different interchangeable algorithms, don't abuse conditional statements, use the Strategy Pattern. It solves your problem beautifully and is very extensible.
 
rinke hoekstra
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mickey,

hm, though applying an object oriented design seems "always" to be good, I'm not too sure about it this time.

I have the feeling that you are seriously overdoing the assignment. Please read the instructions carefully; I doubt that the state that you have to provide AND / OR possibilities.

Also, I don't really see the advantage of wrapping the criteria in an object. Basically, the GUI only wants you to find exact matches for only two fields, nothing more.

I just provided a String[] as a criteria and am not wrapping anything into an object. Not at all Object Oriented. But the great advantage of Object Oriented approach is often smart code reuse; as I don't see any possibility for that over here, I think in this case it is merely overkill.

sorry to be so critical.. maybe it fits good into your overall design and your assignment. But what I get from this assignment is that the main rule is: keep it as simple as possible, and don't do anything which was not asked for.
[ July 10, 2007: Message edited by: rinke hoekstra ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic