Framework Design Guidelines读书笔记

5 篇文章 0 订阅

这本书虽然是讲述.net框架设计的一些规范,不过仍然有一些通用的设计准则可以参考

命名规范:

这些只有在用于公开暴露给外界的API时才是必需的

标识符大小写规则:

1.要把PascalCasing用于由多个单词构成的名字空间,类型以及成员的名字

2.要把camelCasing用于参数的名字

3.不要把闭合形式的复合词中每个单词的首字母大写,比如 callback, endpoint 等等,可以查阅英语词典来确定复合词是不是闭合的

4.不要使用匈牙利命名法。原因有几点,一是发明它的ms公司都已经明确要求在新的库在不要使用这种命名法,二是变量名前加类型标识符是个很不好的习惯,在开发过程中有可能会随时修改这些变量的类型定义,三是新的编辑器中不需要用m_前缀来确定其类型,不过对于内部实现的变量来说,用一个前缀也许会让变量的查找更方便,比如用一个_前缀

5.不要使用未被广泛接受的首字母缩写词,如何确定某个缩写词是否众所周知有个好方法,到google上搜索一下,如果前几条都是你所期望的内容,那么它就是众所周知的了

关于命名:

1.要用名词或名词短语来给类和结构体命名,使用PascalCasing的大小写风格,类名字不要加 C,但是接口前需要加 I,这是个特例

2.用形容词短语来给接口命名,在少数情况下也可以使用名词或名词短语

3.考虑在派生类的末尾使用基类的名字,比如 class FileStream : public Stream

4.用动词或动词短语来命名方法,比如 int CompareTo();

5.要用肯定性的短语(CanSeek而不是CantSeek)来命名布尔属性,可以加Is,Can,Has等前缀,要确保使用时的测试语句读起来通顺,比如

if (collection.Contains(item)) 就比 if (collection.IsContained(item)) 要通顺得多

此外,要优先选择主动语态而不是被动语态,比如

if (stream.CanSeek()) 就比 if (steam.IsSeekable()) 要强得多

6.要用现在时和过去时来赋予事件名以之前和之后的概念,不要用Before或After这样的前后缀,比如 Closing, Closed而不是AfterClose

使用规范:

1.优先使用集合,避免使用数组

2.考虑使用不规则数组,而不要使用多维数组,也就是优先使用int [][] jagedArray这样的数组,避免使用 int [,] multiDimArray这样的类型

3.要用最泛的类型来作为参数类型,大多数以集合为参数的成员都使用IEnumerable 接口

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Framework Design Guidelines, Second Edition, teaches developers the best practices for designing reusable libraries for the Microsoft .NET Framework. Expanded and updated for .NET 3.5, this new edition focuses on the design issues that directly affect the programmability of a class library, specifically its publicly accessible APIs. This book can improve the work of any .NET developer producing code that other developers will use. It includes copious annotations to the guidelines by thirty-five prominent architects and practitioners of the .NET Framework, providing a lively discussion of the reasons for the guidelines as well as examples of when to break those guidelines. Microsoft architects Krzysztof Cwalina and Brad Abrams teach framework design from the top down. From their significant combined experience and deep insight, you will learn * The general philosophy and fundamental principles of framework design * Naming guidelines for the various parts of a framework * Guidelines for the design and extending of types and members of types * Issues affecting-and guidelines for ensuring-extensibility * How (and how not) to design exceptions * Guidelines for-and examples of-common framework design patterns Guidelines in this book are presented in four major forms: Do, Consider, Avoid, and Do not. These directives help focus attention on practices that should always be used, those that should generally be used, those that should rarely be used, and those that should never be used. Every guideline includes a discussion of its applicability, and most include a code example to help illuminate the dialogue. Framework Design Guidelines, Second Edition, is the only definitive source of best practices for managed code API development, direct from the architects themselves. A companion DVD includes the Designing .N ET Class Libraries video series, instructional presentations by the authors on design guidelines for developing classes and components that extend the .NET Framework. A sample API specification and other useful resources and tools are also included.
 2006年JOLT生产效率大奖得主!来自微软。NET框架设计组的智慧结晶, 洞悉。NET技术内幕,.NET开发者的必备图书.   本书为框架设计师和广大开发人员设计高质量的软件提供了权威的指南。书中介绍了在设计框架时的最佳实践,提供了自顶向下的规范,其中所描述的规范普遍适用于规模不同、可重用程序不同的框架和软件。这些规范经历.NET框架三个版本的长斯开发,凝聚了数千名开发人员的经验和智慧。微软的各开发组正在使用这些规范开发下一代影响世界的软件产品。   本书适用于框架设计以及相关的专业技术人员,也适用于高等院校相关专业的学生和教师阅读参考。 -------------------------------------------------------------------------------- 作者简介   Krzysztof Cwalina微软公司公共语言运行库(CLR)的项目经理。他曾为.NET框架的首个版本设计API,并负责任框架中的多个名字空间,包括System.Collections、System.Diagnostics、System.Messaging,等等。他也是FxCop开发组的发起成员之一。目前,他正致力于在整个公司范围内开发推广设计规范,并将其应用到.NET框架和WinFX中。 -------------------------------------------------------------------------------- 编辑推荐   本书为框架设计师和广大开发人员设计高质量的软件提供了权威的指南。书中介绍了在设计框架时的最佳实践,提供了自顶向下的规范,其中所描述的规范普遍适用于规模不同、可重用程序不同的框架和软件。这些规范经历.NET框架三个版本的长斯开发,凝聚了数千名开发人员的经验和智慧。微软的各开发组正在使用这些规范开发下一代影响世界的软件产品。   本书适用于框架设计以及相关的专业技术人员,也适用于高等院校相关专业的学生和教师阅读参考。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值