人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

October 28, 2006

FWK Design Guidelines CD

Filed under: .NET

Transcripts for the MSDN Designing .NET Class Libraries chats (Brad Abrams’ Blog)
http://blogs.msdn.com/brada/archive/2005/07/11/437388.aspx

MSDN: Designing .NET Framework Class Libraries cross index (More chat transcripts by CLR PM)
http://www.bluebytesoftware.com/blog/PermaLink,guid,26be120b-7b86-47f2-bb2c-1c8a063807a5.aspx

Designing .NET Class Libraries (MSDN 所有的讲座)
http://msdn2.microsoft.com/en-us/netframework/aa497250.aspx

————————————-
Setting The Stage
by Brad Abrams
————————————-

————————————
API Usability
by Steven Clarke(http://blogs.msdn.com/stevencl/default.aspx)
http://msdn.microsoft.com/chats/transcripts/net/2005_0223_apiusability.aspx
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20040929usability/manifest.xml&rate=1
————————————
了解API的使用者(Target audience),提供易用,好懂的API

1.如何收集反馈,在开发周期中检查是否达到设计目标
2.API的3重境界:
能工作
易懂的API,用户明白如何工作,
用户可以预测(predict)如何使用

3.没有程序员愿意学习如何使用API

4.如何设计API
从设计开始就注意
Use the Cognitive Dimensions
Understand users’ scenarios.
Get feedback

5. Cognitive Dimensions
abstraction level
Learning Style : Top down
Working Framework : work set
Work-Step Unit : Develop 完成一个工作所需的步骤
Premature Commitment
Progressive Evaluation
9. Gathering User Feedback
Early and often
API review
Expreience review
Usablity study

14. Common Usability Problems

————————————-
Designing Progressive APIs
by Krzysztof Cwalina {CLR Team PM}
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20040929prog_apis/manifest.xml&rate=2
————————————-
3种程序员
1. Vertical
2. Pragmatic
3. Einsteins
vb, MFC, ATL

Progressive API
1.易学:
80/20 Rule
Defaults and helps
2.Powerful
Richness
Performance
Scalablity
3.Consistent

设计原则: Scenario-Driven
Defing top scenario
Write code samples first, design API later
Make top scenario easy, make the rest possible
Usablity test top scenarios

设计原则2: Supporting experimentation

设计原则3: Aggregate component

设计原则4: Self-Documenting APIs
命名
Exception
设计原则5: Keeping Things Simple
Number of objects
Dependencies
Lines of code
OO

————————————-
Designing Inheritance Hierarchies
by Brad Abrams
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20040929hierarchies/manifest.xml&rate=2
————————————-
Keywords: Interface versus base class
So you can do the minimum now, and then add more to it in the future.

Overriding的思考点:
1.不要改变base class 定义的 contract
2.通常需要call base, 除非有充足的理由.
3.不要让class写出这样的code:
if( obj is network stream) …
else if(obj is …) …

Interface
Explicit Implementation

————————————-
FxCop in Depth
by Jeffrey Van Gogh, Michael Murray
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20041012fxcop/manifest.xml&rate=0
http://www.microsoft.com/china/msdn/events/webcasts/shared/msdntv/episode.aspx?xml=/china/msdn/events/webcasts/msdntv/20031204FxCopMM/manifest.xml
————————————-
FxCop干了什么:
Access IL metadata
Examine IL method bodies
Walk call graphs
Determine some argument
Use spelling checker (if office is installed)
规则分类:
COM
Design
Globalization
Naming
Performance
Usage
Security
Custom

————————————-
Designing for Managed Memory World(经典!)
by Brad Abrams
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20040929memory_world/manifest.xml&rate=1
————————————-
Framework的作者需要封装native 资源
~ 被编译器翻译为
protected override void Finalize()
{
try
{

}
finally
{
base.finalize();
}
}

何时需要~即 Finalize()
仅在需要释放外部资源时.

Dispose Pattern
Dispose()会 被多次调用
Dispose()不能throw exceptiion
if(disposed)
throw new ObjectDisposedException();

使用:
using( Resource res = new Resource())
{
res.DoWork();
}

GC.AddMemoryPressure()
GC.RemoveMemoryPressure()

HandleCollector
.NET Framework 2.0 中新增。
跟踪未处理的句柄,并在达到指定阈值时强制执行垃圾回收。

————————————-
Member Types
by Brad Abrams
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20040929member_types/manifest.xml&rate=2
————————————-
1.Constructor
在c++中不要在一个Constructor中throw exception.
在c#中可以这样做,Finalizer仍旧可以调用,GC仍旧可被执行.

永远显式定义一个default constuctor,以免错误:
//v1
public class Foo
{
}
此时 Foo f = new Foo(); 正常工作

//v2
pubolc class Foo
{
public Foo(int value)
}
此时 Foo f = new Foo(); 出错

So what that essentially means is between the two releases, you’ve removed the default
one and added this new one, so that will break code.

2. Overloading
参数少的函数会假定传入defatul value
参数的顺序要一致,参数最多的函数最好定义为virtual

Performance:
使JIT生成 in-line函数:
少使用virutal method
不要定义过多的局部变量

Property and Method:
property 返回不变的值如: string Name{get;},
从逻辑上说是一个data member
method 返回变化的值: Guid GetNext(){};conversion,
复杂的逻辑
可能不会马上返回.

不要定义用来生成snapshotting的array 类型的property,, 防止这样的写法:
for(int i= 0; i < list.Length; i++)
{
list.All[i]….
}

Event Pattern
protected void DoClick()
{
PaintDown();
try
{
onClick(); //call event handler
}
finally
{
if(windowHandler != null)
{
PaintUp();
}
}
}

Static Member 的用途及使用pattern
Singleton Pattern
Factory methods

Ref and Out Parameters:
主要用于interop
Ref是CLR的特性
Out是c#的属性

————————————-
Naming Conventions
by Brad Abrams
http://msdn2.microsoft.com/en-us/netframework/aa497259.aspx
————————————-
All type and publicly exposed member are PascalCased
Parameter are camelCased

So also the principle of least surprise, you want to do what developers expect.

Type Naming:
1.使用名词
2.如果从Exception派生, 命名为ArgumetException
————————————-
Packaging, Assemblies and Namespaces
by Michael Murray (Longhon SDK Team PM)

Assemply 和Namespace 为什么要使用不同的名字?
Assemply名称使人易于找出需要reference的dll
不同版本的Type最好位于不同的assembly.
同一个Assemlby中的代码的信任级别是相同的.
改动会引发rebuild

————————————-

————————————-
Performance
by Rico Mariani, Maoni Stephens
————————————-

————————————-
Rich Type System

————————————-

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2006/10/28/fwk-design-guidelines-cd/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham