框架设计准则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避免Avoid和`不要 `Do 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.

这些准则摘自本书Framework 设计准则:约定、 语法和模式的可重用的.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.

经 Pearson Education, Inc 授权,转载自框架设计准则:可重用的 .NET 库的约定、习惯用语和模式,第 2 版 作者:Krzysztof Cwalina 和 Brad Abrams,由 Addison Wesley Professional 于 2008 年 10 月 22 日印发,作为 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