框架设计准则Framework Design Guidelines

本部分提供了有关设计扩展和与 .NET Framework 进行交互的库的指南。This section provides guidelines for designing libraries that extend and interact with the .NET Framework. 其目标是通过提供与用于开发的编程语言无关的统一编程模型,来帮助库设计人员确保 API 一致性和易用性。The goal is to help library designers ensure API consistency and ease of use by providing a unified programming model that is independent of the programming language used for development. 建议在开发扩展 .NET Framework 的类和组件时遵循这些设计指导原则。We recommend that you follow these design guidelines when developing classes and components that extend the .NET Framework. 不一致的库设计会对开发人员工作效率产生负面影响,并防止采用。Inconsistent library design adversely affects developer productivity and discourages adoption.

本指南被组织为简单的建议,其前缀为 Do 、、 Consider AvoidDo notThe guidelines are organized as simple recommendations prefixed with the terms Do, Consider, Avoid, and Do not. 这些准则旨在帮助类库设计人员了解不同解决方案之间的权衡。These guidelines are intended to help class library designers understand the trade-offs between different solutions. 在某些情况下,良好的库设计需要你违反这些设计准则。There might be situations where good library design requires that you violate these design guidelines. 这种情况应该很少见,因此您有一个清晰且引人注目的决策理由。Such cases should be rare, and it is important that you have a clear and compelling reason for your decision.

这些指导原则摘录内容于本书框架设计指南:约定、惯例和模式,适用于可重复使用的 .Net 库第2版,通过 Krzysztof Cwalina 和 Brad Abrams。These guidelines are excerpted from the book Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries, 2nd Edition, by Krzysztof Cwalina and Brad Abrams.

本节内容In This Section

命名准则Naming Guidelines
提供用于命名类库中的程序集、命名空间、类型和成员的准则。Provides guidelines for naming assemblies, namespaces, types, and members in class libraries.

类型设计准则Type Design Guidelines
提供使用静态和抽象类、接口、枚举、结构和其他类型的指导原则。Provides guidelines for using static and abstract classes, interfaces, enumerations, structures, and other types.

成员设计准则Member Design Guidelines
提供设计和使用属性、方法、构造函数、字段、事件、运算符和参数的准则。Provides guidelines for designing and using properties, methods, constructors, fields, events, operators, and parameters.

扩展性设计Designing for Extensibility
讨论扩展性机制(如子类化、使用事件、虚拟成员和回调),并说明如何选择最能满足框架要求的机制。Discusses extensibility mechanisms such as subclassing, using events, virtual members, and callbacks, and explains how to choose the mechanisms that best meet your framework's requirements.

异常设计准则Design Guidelines for Exceptions
介绍设计、引发和捕获异常的设计准则。Describes design guidelines for designing, throwing, and catching exceptions.

使用准则Usage Guidelines
介绍使用常见类型(如数组、特性和集合、支持序列化和重载相等运算符)的准则。Describes guidelines for using common types such as arrays, attributes, and collections, supporting serialization, and overloading equality operators.

常见设计模式Common Design Patterns
提供有关选择和实现依赖项属性的准则。Provides guidelines for choosing and implementing dependency properties.

部分©2005,2009 Microsoft Corporation。保留所有权利。Portions © 2005, 2009 Microsoft Corporation. All rights reserved.

皮尔逊教育,Inc. 的经许可重印权限:从框架设计指导原则:用于可重复使用的 .Net 库的约定、惯例和模式、第2版By Krzysztof Cwalina 和 Brad Abrams,发布十月22,2008,作为 Microsoft Windows 开发系列的一部分。Reprinted by permission of Pearson Education, Inc. from Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries, 2nd Edition by Krzysztof Cwalina and Brad Abrams, published Oct 22, 2008 by Addison-Wesley Professional as part of the Microsoft Windows Development Series.

另请参阅See also