Is there an example of the full builder pattern in the .NET base class library? I'm looking for something that has an actual director and multiple concrete builders.
I'm far from an expert in this area, but I think that DbCommandBuilder and its inheriting classes (OdbcCommandBuilder, OleDbCommandBuilder, SqlCommandBuilder) might be an example...if it's OK that the abstract builder base class also serves as the director. The various concrete classes delegate to their base class, which then calls methods like these (per 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 of the requirements to be a builder:
BuildDeleteCommand
, BuildInsertCommand
, BuildUpdateCommand
)DbCommand
, cast to a specific command type by the concrete classes) which is more complex than just a SQL string, because it has a timeout, a command type, potentially a transaction, etc.But there's not a separate class serving as the director; in effect, the DbCommandBuilder
base class is the director.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With