用于.NET框架的设计模式? [英] Design patterns used in the .NET framework?

查看:224
本文介绍了用于.NET框架的设计模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要增加你的设计模式的理解的一种方法是,以发现如何图案在.NET框架中使用。

One way to increase your understanding of design patterns is to discover how patterns are used in the .NET framework.

你有没有发现,设计模式任何的例子在.NET框架?在你的答案请给​​图案的简短说明它是如何使用的框架,例如。

Have you found any examples of design patterns in the .NET framework? In your answer please give a short description of the pattern, and example of how it is used in the framework.

示例答案:

战略设计模式脱钩从使用它的算法封装到一个单独的类的类的算法。这允许算法切换

The Strategy Design Pattern decouples an algorithm from the class that uses it by encapsulating the algorithm into a separate class. This allows for switching of algorithms.

List类的排序方法是策略模式的一个例子。

The Sort method of the List class is an example of the Strategy pattern.

public void Sort(IComparer<T> comparer)

通过接受一个的Icomparable接口类的用户可以在运行时切换排序算法。

By accepting an IComparer interface, users of the class can switch the sorting algorithm at runtime.

推荐答案

装饰图案是用在Stream类:

The Decorator Pattern is used on the Stream classes:

  • 的System.IO.Stream
    • System.IO.BufferedStream
    • System.IO.FileStream
    • System.IO.MemoryStream
    • System.Net.Sockets.NetworkStream
    • System.Security.Cryptography.CryptoStream
    • System.IO.Stream
      • System.IO.BufferedStream
      • System.IO.FileStream
      • System.IO.MemoryStream
      • System.Net.Sockets.NetworkStream
      • System.Security.Cryptography.CryptoStream

      该子类装饰流,因为他们继承它,而且他们还含有流的,它被设置在构造函数中的一个实例。

      The subclasses decorate Stream because they inherit from it, and they also contain an instance of Stream that is set up in the constructor.

      这篇关于用于.NET框架的设计模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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