标准结构:

.Net Framework中使用的模式-Factory模式

WebRequest结构:

.Net Framework中使用的模式-Factory模式

在WebRequst中,不存在独立的Factory类,而是将创建方法做为产品基类的静态方法。这是一种工厂方法的常见变形。Create方法伪码:

public abstract class WebRequest

{
    public static WebRequest Create(string url)
    {
        if(url.BeginWith(“file://”))
            return new FileWebRequest();
        if(url.BeginWith(“ftp://”))
            return new FtpRequest();
        if(url.BeginWith(“file://”))
            return new HttpWebRequest();
    }
}

相关文章:

  • 2021-11-30
  • 2021-04-30
  • 2022-12-23
  • 2022-01-29
猜你喜欢
  • 2022-02-24
  • 2022-01-20
  • 2021-07-11
  • 2021-12-01
  • 2021-07-16
相关资源
相似解决方案