PD-DM Query Interface
Since the PD object shouldn't know anything about the DM interface, but
needs to be able to query values from the database, what is the "right" OO
method for handling user queries?
Example:
TCustomer = class(TPDObject)
public
constructor Create; // Creates a blank customer
procedure FindByName(Name: string); // Should I do this?
procedure Find(Criteria: string); // Or this?
end;
and given the above, since the PD object should know nothing about the
database (DM object), then how does the PD object pass the query to the DM
object to get data?
Is there a better way or examples of how to accomplish this?
I've thought about using an separate "lookup" class, unique to each
PDObject, but that seems a little clunky and I'd like to keep the interface
clean so that I can just call Person.FindByLastName('Bubba'); Putting
multiple search criteria is also a little problem. If I want to search by
first AND last name, the "FindByLastName" method won't really cut the
mustard.
I envision a query class (TPDQuery?) that has "properties" and "values"
added to it for search criteria. Something like this...
TPDQueryFunction = (qAND, qOR, qNOT);
procedure TPDQuery.Select(Function: TPDQueryFunction; const Property:
string; const Value: Integer); overload;
procedure TPDQuery.Select(Function: TPDQueryFunction; const Property:
string; const Value: string); overload;
procedure TPDQuery.Select(Function: TPDQueryFunction; const Property:
string; const Value: TDateTime); overload;
This object could be created and passed to a generic "Find" interface of the
PD Object, which would work. I'm just not quite sure which direction is the
right way to go.
Comments?
Eric