Need for the Delegate Solution?
Well, there might
be situations when you need the old solution with the delegate, but for
the most part I dont think you do. If
you do need it, you have to
add the methods again that I have dropped from the Unit of Work classes.
Those were AddResultHander()
I touched upon
the Query Object  several times in part 3  and 4  where I showed
how to use it for setting criteria in Query Object instances.
purpose of the Query Object  pattern is to encapsulate all information
for a query that is needed to execute the query against the database.
As you saw in
Listing 7, I then take out the criteria information from the Query Object,
and use the criteria values directly as parameters to my stored procedures.
Of course, this is just an example and a simple one at that, but you can
use this solution as the basis for solving much more complex problems too.
you might remember, in part 3  I also used the CustomerQuery
for consumer-side filtering, so you dont only have to use Query Objects
when accessing the database, of course.
My current implementation
of Query Object classes such as CustomerQuery inherits
from the MustInherit
class QueryBase. You'll find the QueryBase class and
an example of a subclass (CustomerQuery)
in Figure 4.
The QueryBase class
As you saw in Listing
7, Criteria() is used for taking
out criteria values from the Query Object. Also note that the AddParameter()
methods of the Unit of Work classes use named parameters (for example @myParameter='TheValue') when calling
the stored procedures. Because of this and as a result of default values for
the parameters in the definitions of the stored procedure, its okay to not
set all parameters explicitly in the call.
How are criteria
set? By setting WriteOnly properties of subclasses such as setting CustomerNo in Figure
4 to the value 5, for instance.
Finally, by letting the Query Object support consumer side filtering too,
the subclasses must override the Match()
So, to implement
a Query Object, what you have to write is the code
for the criteria properties and the Match() method. An example of that code is found in
Property Name() As