问题描述
是否有.NET基类库中完整构建器模式的示例?我正在寻找一个具有实际导演和多个具体建设者的东西。
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.
推荐答案
我远不是这个专家区域,但我认为 及其继承类(,,)可能是一个例子...如果可以的话抽象建设者基础班也担任导演。各种具体的类委托给他们的基类,然后调用这些方法(每个Reflector):
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:
- 抽象构建器类
- 具体构建器类
- 复杂的多步骤构建在各种DbCommandBuilder方法(
BuildDeleteCommand
,BuildInsertCommand
,BuildUpdateCommand
) - product(
DbCommand
,转换为具体类的特定命令类型),它比只是一个SQL字符串更复杂,因为它有超时,命令类型,潜在的交易等。
- abstract builder class
- concrete builder classes
- complex multi-step building in the various DbCommandBuilder methods (
BuildDeleteCommand
,BuildInsertCommand
,BuildUpdateCommand
) - product (
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.
但是没有一个单独的课程担任导演;实际上, DbCommandBuilder
基类是导演。
But there's not a separate class serving as the director; in effect, the DbCommandBuilder
base class is the director.
这篇关于在.NET BCL中有Builder Builder的示例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!