Query Object

In PatternsOfEnterpriseApplicationArchitecture a QueryObject provides a means to join multiple criteria much like a SQL statement. Eventually, the query can be executed (using execute()), which causes the query to be rendered to an SQL statement.

I think the PatternsOfEnterpriseApplicationArchitecture is an excellent book. I was particularly impressed with the descriptions of mappers and the domain model. However, I find myself questioning the QueryObject pattern.

QueryObjects contain one or more Criteria objects, which contain an operator, a field, and a value. In the field, we are supposed to use the name of private fields so that a Metadata Mapping can transform the query from a domain query to a relational database query. This seems like a violation of ObjectOrientedProgramming. Now some client of a DomainObject must know its internal details. Furthermore, if that detail ever changes, the client must be updated, but there is no obvious way to inform the client because they rely on internals of the DomainObject.

One alternative that I can think of, though not much prettier, would be to expose the field names as public static final fields for the DomainObject. In this case, the client could be insulated from changes to the field name, but it is still, in a way, exposing internals of the class.

PleaseComment


EditText of this page (last edited March 31, 2003) or FindPage with title or text search