• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

B&S: Search Criteria + DAO's

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?

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.
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 ]
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic