34.15. Consolidating and Hiding SQL Statements in One Class

Hard-coding SQL statements into different RDB mapper classes is not a terrible sin, but it can be improved upon. Suppose instead:

  • There is a single Pure Fabrication class (and it's a singleton) RDBOperations where all SQL operations (SELECT, INSERT, ...) are consolidated.

  • The RDB mapper classes collaborate with it to obtain a DB record or record set (for example, ResultSet).

  • Its interface looks something like this:

    								class RDBOperations
    								{
    								public ResultSet getProductSpecificationData( OID oid ) {...}
    								public ResultSet getSaleData( OID oid ) {...}
    								...
    								}
    							

So that, for example, a mapper has code like this:

						class ProductSpecificationRDBMapper extends AbstractPersistenceMapper
						{
						protected Object ...

Get Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and the Unified Process, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.