Software Design Patterns in C#

本文介绍了软件设计模式的基本概念及其在C#中的应用。涵盖了创建型、结构型及行为型三大类共23种经典设计模式,并提供了每种模式的简单解释、UML类图及示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

软件设计模式C#

Software Design Patterns in C#

 

设计模式(Design Patterns)是你在实际应用程序开发中,对不断发现的软件设计问题的重复解决方案。设计模式是关于对象的设计和交互,关于对经常出现的软件开发挑战的一些完美和重用的解决方案,也提供了一个交流平台,

 

“四人帮”(GOF)模式被认为是所有其他模式的基础,23种设计模式分为3类:创建型模式(Creational Pattern),结构型模式(Structural Pattern)和行为型模式(Behavioral Pattern)。

 

为了让你先起步,这里提供了2种形式的源码:结构方面的(structural)和现实应用方法的(real-world)。结构方面的代码使用模式定义和UML类图中提供的类型名称,而实际应用方面的代码提供了你需要使用模式的真实设计情况。

 

  Creational Patterns 创建型模式

  Abstract Factory

  Creates an instance of several families of classes

  Builder

  Separates object construction from its representation

  Factory Method

  Creates an instance of several derived classes

  Prototype

  A fully initialized instance to be copied or cloned

  Singleton

  A class of which only a single instance can exist

 

  Structural Patterns 结构型模式

  Adapter

  Match interfaces of different classes

  Bridge

  Separates an object’s interface from its implementation

  Composite

  A tree structure of simple and composite objects

  Decorator

  Add responsibilities to objects dynamically

  Façade

  A single class that represents an entire subsystem

  Flyweight

  A fine-grained instance used for efficient sharing

  Proxy

  An object representing another object

 

  Behavioral Patterns 行为型模式

  Chain of Resp.

  A way of passing a request between a chain of objects

  Command

  Encapsulate a command request as an object

  Interpreter

  A way to include language elements in a program

  Iterator

  Sequentially access the elements of a collection

  Mediator

  Defines simplified communication between classes

  Memento

  Capture and restore an object's internal state

  Observer

  A way of notifying change to a number of classes

  State

  Alter an object's behavior when its state changes

  Strategy

  Encapsulates an algorithm inside a class

  Template Method

  Defer the exact steps of an algorithm to a subclass

  Visitor

  Defines a new operation to a class without change

 

 

原英文URL

http://www.dofactory.com/Patterns/Patterns.aspx#list

 

上述各类模式的链接均提供了简单的解释、UML类图、Structural codeC#)和Real-world codeC#)。

设计模式:可重用的面向对象软件的基本元素(Design Patterns: Elements of Reusable Object-Oriented Software)”是一本由 Erich Gamma、Richard Helm、Ralph Johnson 和 John Vlissides 四人所著的经典书籍。该书于1994年首次出版,被誉为“软件设计模式圣经”。 该书讲述了一些经典的设计模式,包括面向对象编程中涉及到的对象、类、接口和继承等基本概念,并详细介绍了在实际应用中如何使用这些模式来解决常见的设计问题。 该书的主要内容包括:介绍了23种设计模式,其中分为创建型模式(Creational Patterns)、结构型模式(Structural Patterns)和行为型模式(Behavioral Patterns)三种类型;每个设计模式包括模式的定义、优点、结构以及应用场景等方面,以及一些常见的解决方案;此外,该书还特别强调了设计模式的重要性,并简要介绍了如何利用设计模式提高代码的可维护性和可重用性等方面。 该书的读者主要包括软件开发人员、软件架构师、系统设计师等技术人员,也适合经验较浅的Java、C++和C#等编程语言的初学者,读过该书后可以深刻理解并熟练运用设计模式来提高软件开发的效率和质量。 在优快云(中文技术社区)上,设计模式是一门热门的技术,有很多人通过阅读“设计模式:可重用的面向对象软件的基本元素”这本书籍,来掌握设计模式的基础知识,并学习如何在实际项目中应用这些模式。该书也经常被提及在优快云社区中的技术讨论中,并被认为是学习设计模式最权威的教材之一。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值