有没有在.NET BCL Builder模式的例子吗? [英] Is there an example of the Builder Pattern in the .NET BCL?

查看:148
本文介绍了有没有在.NET BCL Builder模式的例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在.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.

推荐答案

我远离这个领域的专家,但我的认为的是<一href="http://msdn.microsoft.com/en-us/library/system.data.common.dbcommandbuilder.aspx">DbCommandBuilder其继承类(<一href="http://msdn.microsoft.com/en-us/library/system.data.odbc.odbccommandbuilder.aspx">OdbcCommandBuilder, <一href="http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommandbuilder.aspx">OleDbCommandBuilder, <一href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspx">SqlCommandBuilder)可能是一个例子...如果它是确定的抽象建设者基类还担任导演的各种具体类委托给他们的基类,然后调用这样的方法(每反射):

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
  • 产品(的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模式的例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆