如何设计一个好的API ?为什么它如此重要(API设计过程)

以适当的怀疑态度收集需求

  1. 多听取他人的建议
    ––也许存在更好的方案
  2. 你的工作是提取真正的需求
    ––应该采用用例的形式
  3. 建造更一般的东西往往更简单,回报也更高

以一个《简短的说明》开始 –– 一页纸就够了

  1. 在这个阶段,敏捷性胜过完整性
  2. 迅速采集尽可能多的需求
    ––倾听他们的意见并认真对待
  3. 如果你保持说明书简短,就很容易修改
  4. 通过编码及时实现自己的想法

尽早编写并及时修改

  1. Start before you’ve implemented the API
    –– 减少无效工作
    2.Start before you’ve even specified it properly
    –– Saves you from writing specs you’ll throw away
  2. 在充实API的过程中持续编写API
    –– 防止令人讨厌的意外
    –– 代码基于用例、单元测试而存在

Writing to SPI is Even More Important

  1. Service Provider Interface (SPI)
    –– Plug-in interface enabling multiple implementations
    –– Example: Java Cryptography Extension (JCE)
  2. Write multiple plug-ins before release
    –– If you write one, it probably won’t support another
    –– If you write two, it will support more with difficulty
    –– If you write three, it will work fine
  3. Will Tracz calls this “The Rule of Threes”
    (Confessions of a Used Program Salesman, Addison-Wesley, 1995)

Maintain Realistic Expectations

  1. Most API designs are over-constrained
    –– You won’t be able to please everyone
    –– Aim to displease everyone equally
  2. Expect to make mistakes
    –– A few years of real-world use will flush them out
    –– Expect to evolve API
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值