I am far from an expert in this field, but I think that DbCommandBuilder and its inheriting classes ( OdbcCommandBuilder , OleDbCommandBuilder , SqlCommandBuilder ) can be an example ... if it is so, that the base class of the abstract builder also acts as a director. Various concrete classes delegate them to the base class, which then calls such methods (for the reflector):
private DbCommand BuildDeleteCommand(DataTableMapping mappings, DataRow dataRow) { DbCommand command = this.InitializeCommand(this.DeleteCommand); StringBuilder builder = new StringBuilder(); int parameterCount = 0; builder.Append("DELETE FROM "); builder.Append(this.QuotedBaseTableName); parameterCount = this.BuildWhereClause( mappings, dataRow, builder, command, parameterCount, false); command.CommandText = builder.ToString(); RemoveExtraParameters(command, parameterCount); this.DeleteCommand = command; return command; }
This fulfills some requirements for the builder:
- abstract constructor class
- concrete builder classes
- complex multi-stage construction in various methods of DbCommandBuilder (
BuildDeleteCommand , BuildInsertCommand , BuildUpdateCommand ) - (
DbCommand is discarded by a specific command type by specific classes), which is more complex than just an SQL string, because it has a timeout, command type, potentially a transaction, etc.
But there is no separate class acting as a director; in fact, the base class of DbCommandBuilder is a director.
source share