扩展性设计Designing for Extensibility

设计一个框架的一个重要方面是确保仔细考虑框架的可扩展性。One important aspect of designing a framework is making sure the extensibility of the framework has been carefully considered. 这要求你了解与各种可扩展性机制相关的成本和收益。This requires that you understand the costs and benefits associated with various extensibility mechanisms. 本章可帮助你确定哪些可扩展性机制(子类、事件、虚拟成员、回调等)可以最好地满足框架的要求。This chapter helps you decide which of the extensibility mechanisms—subclassing, events, virtual members, callbacks, and so on—can best meet the requirements of your framework.

有许多方法可以在框架中实现可扩展性。There are many ways to allow extensibility in frameworks. 有些方法功能不强但成本较低,有些方法功能强大但成本较高。They range from less powerful but less costly to very powerful but expensive. 对于任何给定的可扩展性要求,应该选择满足要求的成本最低的可扩展性机制。For any given extensibility requirement, you should choose the least costly extensibility mechanism that meets the requirements. 请记住,通常可以在以后添加更多的可扩展性,但不能在不引入中断性变更的情况下将其删除。Keep in mind that it’s usually possible to add more extensibility later, but you can never take it away without introducing breaking changes.

本节内容In This Section

未密封类Unsealed Classes
受保护的成员Protected Members
事件和回调Events and Callbacks
虚拟成员Virtual Members
抽象(抽象类型和接口)Abstractions (Abstract Types and Interfaces)
用于实现抽象的基类Base Classes for Implementing Abstractions
密封Sealing
部分©2005,2009 Microsoft Corporation。保留所有权利。Portions © 2005, 2009 Microsoft Corporation. All rights reserved.

*在 Pearson Education, Inc. 授权下,由 Addison-Wesley Professional 作为 Microsoft Windows 开发系列的一部分再版自 Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries, 2nd Edition(Framework 设计准则:可重用 .NET 库的约定、惯例和模式第 2 版),由 Krzysztof Cwalina 和 Brad Abrams 发布于 2008 年 10 月 22 日。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