[Framework Design Guideline]基础知识

最近在读<Framework design guideline>, 感觉其中Framework的许多设计经验同样适用于业务类库的设计,甚至对于服务的设计也同样适用。

日常的设计和编码中,书中提到的许多原则也有所领悟,但一直无法系统的组织起来。

所以此文把这些指导经验都整理起来,一作为备忘,二也是为这些平常只能靠感觉的东西建立成文的指导。本文只整理了一些对于业务应用类库开发更有用的原则。

一、什么是好的设计

  • Well-Designed Frameworks are simple.
  • Well-Designed Frameworks are expensive to design.
  • Well-Designed Frameworks are full of trade-offs.
  • Well-Designed Frameworks borrow from the past.
  • Well-Designed Frameworks are designed to evolve.
  • Well-Designed Frameworks are integrated.
  • Well-Designed Frameworks are consistent.

二、如何做出好的设计

Design frameworks that are both powerful and easy to use.

好的类库/框架应该既能满足复杂的业务场景又易于使用。也就是简单的事情简单做,复杂的事情可以做。

The Principle of scenario-driven design.

Make sure that the API design specification is the central part of the design of any feature that includes a publicly accessible API.

Define top usage scenarios for each major feature area.

Ensure that the scenarios correspond to an appropriate abstraction.

Design APIs by first writing code samples for the main scenarios and then defining the object model to supprot the code samples.

Don’t rely solely on standard design methodologies when designing the public API layer of a framework.

在设计一个公共类库的时候,不要单独依赖某一种设计方法,包括一些经典的面向对象的设计方法。因为这些方法可能更多的针对可维护性,而不是framework的可用性。

最好使用场景驱动、原型、可用性研究等方法,再配合迭代。

Organize usability studies to test APIs in main scenarios.

应该在开发早期就对主要业务场景进行可用性研究,因为可用性的问题可能导致底层设计的改变。

The Principle of Low Barrier to Entry

Ensure that each main feature area namespace contains only types that are used in the most common scenarios.

Types used in advanced scenarios should be place in subnamespaces.

Provide simple overloads of constructors and methods. A simple overload has a very small number of parameters, and all parameters are primitives.

Don’t require users to explicitly instantiate more than one type in the most basic scenarios. 
Don’t require that users perform any extensive initialization before they can start programming basic scenarios.

Provide good defaults for all properties and parameters.

Communicate incorrect usage of APIs using exceptions.

异常应该能够清楚表达什么导致了这个异常,并描述如果处理。

The Principle of Self-Documenting Object Models

Ensure that APIs are intuitive and can be successfully used in basic scenarios without referring to the reference documentation.

Provide great documentation with all APIs.

Make the discussion about identifier naming choices a significant part of specification reviews.

Don’t be afraid to use verbose identifier names.

Consider reserving the best type names for the most commonly used types.

Use exception messages to communicate framework usage mistakes to the developer.

Provide strongly typed APIs if at all possible.

Avoid many abstractions in mainline scenario APIs.

The Principle of Layered Architecture

Using a layered framework with high-level APIs optimized for productivity, and using low-level APIs optimized for power and expressiveness.

Avoid mixing low-level and high-level APIs in a single namespace if the low-level APIs are very complex.

[Framework Design Guideline]的更多相关文章

  1. [书籍]重温《Framework Design Guidelines》

    1. 前言 最近重温了<Framework Design Guidelines>. <Framework Design Guidelines>中文名称为<.NET设计规范 ...

  2. learn from collection framework design

    最难忍受的痛苦,也许是想干一件事情而又不去干.--罗曼·罗兰 前言 本篇文章算是拾人牙慧吧,偶尔谷歌到一个能很好把collection framework design讲好的文档,一是为了总结提升,也 ...

  3. Automation Framework Design 自动化框架设计思想

    从2007年到2017年,十年内自动化测试工具层出不穷,各种工具在运用一段时间之后,各个公司都会有测试架构师对于目前的自动化测试工具进行框架定制设计. 从惠普2007年GDCC推出的的WebDrivi ...

  4. .NET 学习书籍推荐

    时间过得好快啊,转眼三月过了1周多了,今天把看书的目录记录下,方便初学者 最近由于项目需要研究下dotnet 技术,参考书籍如下: 1.深入理解C# 2.CLR via  C# 3.Framework ...

  5. C# 必看书籍

    C# in Depth:讲的是C#的东西.CLR via C#:讲的是运行时的东西.Framework Design Guideline:讲的是你要如何设计一个类库才能跟.NET浑然一体.——“赵三本 ...

  6. 标准IDispose模式浅析

    DoNet资源 众所周知,.Net内存管理分托管资源和非托管资源,把内存中的对象按照这两种资源划分,然后由GC负责回收托管资源(Managed Resource),而对于非托管资源来讲,就需要程序员手 ...

  7. .net 程序员成长路线图?

    https://www.zhihu.com/question/25474641 得看赵四本, @赵劼 推荐的. CLR via C# .net Essentials C# in Depth Frame ...

  8. Entity Framework技巧系列之一 - Tip 1 - 5

    提示1. 在Entity Framework中怎样排序关系(Relationships) 问题: 在Entity Framework论坛中常会看到关于排序相关联项目的问题. 例如,想象你要查询客户,并 ...

  9. ios项目里扒出来的json文件

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0. ...

随机推荐

  1. hdu 4115 石头剪子布(2-sat问题)

    /* 意甲冠军:石头剪子布,目前已知n周围bob会有什么,对alice限制.供u,v,w:设w=0说明a,b回合必须出的一样 否则,必须不一样.alice假设输一回合就输了,否则就赢了 解: 2-sa ...

  2. JavaScript循环之for/in循环

    今天学到了JavaScript的语句篇.同其他常见编程语言如C.Java等一样,JavaScript中的语句包含:①表达式语句②复合语句和空语句③声明语句④条件语句⑤循环语句⑥跳转语句,当然JavaS ...

  3. Struts2流程

    Struts2流程 1.client浏览器初始化时发出HTTP请求 2.依据web.xml配置,上述请求被FilterDispatcher接收 3.依据struts.xml配置,找到须要调用的Acti ...

  4. JavaScript之再谈回调与闭包

    前些阵子写了几篇关于回调和闭包的博文,感觉自己都是似懂非懂,最近在项目中又碰到了类似的情况,故在此咱们来重弹js中的回调与闭包. 先说说回调: 百度百科: 回调函数就是一个通过函数指针调用的函数.如果 ...

  5. [置顶] Spring中DI设置器注入

    Java的反射机制可以说是在Spring中发挥的淋漓尽致,下面要看的代码就是通过反射机制来实现向一个类注入其实际依赖的类型,这个过程的实现会交由Spring容器来帮我们完成. JavaBean中针对属 ...

  6. crawler_如何从页面获取新浪cookie

    步奏如下: 1 用chrome浏览器(其他浏览器原理相同)打开地址: http://weibo.com/ 2.点击鼠标右键 右键点击查看元素 点击Network   3.输入用户名  密码 执行登录 ...

  7. Redhat Linux挂载NTFS格式的移动硬盘

    Redhat Linux挂载NTFS格式的移动硬盘 1. 选择下载ntfs-3g的源码包或rpm包 http://www.tuxera.com/community/open-source-ntfs-3 ...

  8. maven_修改setting ,改为自己私服或者OSC开源中国 [为解决sqlite-jdbc 在中央仓库找不到]

    因为项目要使用到sqlite ,虽然有现成的jar,但是考虑的项目的易用统一管理,决定还是用maven 结果纠结了半天 sqlite-jdbc 在maven默认的仓库根本找不着,于是乎修改 setti ...

  9. jQuery按回车键执行指定方法

    1.按Enter键执行指定方法: //按回车进入页面 $(function(){ $(document).keydown(function(event){ if (event.keyCode == 1 ...

  10. 给Notepad++ 6.7 加右键菜单带图标

    使用的是Notepad++ 6.7,下载 NppShell64.dll 和 NppShell.dll方法:将BAT文件和下载的NppShell64.dll 和 NppShell.dll放置Notepa ...