ImageVerifierCode 换一换
格式:PPT , 页数:21 ,大小:272KB ,
资源ID:378472      下载积分:2000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-378472.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(API Design.ppt)为本站会员(outsidejudge265)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

API Design.ppt

1、API Design,CPSC 315 Programming Studio Spring 2009,Follows Kernighan and Pike, The Practice of Programming and Joshua Blochs Library-Centric Software Design 05 Keynote Talk: ”How to Design a Good API and Why It Matters”,API,Application Programming Interface Source code interface For library or OS Pr

2、ovides services to a program At its base, like a header file But, more complete,Why is API Design Important?,Company View Can be asset big user investment in learning and using Bad design can be source of long-term support problems Once used, its tough to change Especially if there are several users

3、 Public APIs One chance to get it right,Characteristics of Good APIs,Easy to learn Easy to use even without documentation Hard to misuse Easy to read and maintain code that uses it Sufficiently powerful to satisfy requirements Easy to extend Appropriate to audience,Designing an API,Gather requiremen

4、ts Dont gather solutions Extract true requirements Collect specific scenarios where it will be used Create short specification Consult with users to see whether it works Flesh it out over time Hints: Write plugins/use examples before fully designed and implemented Expect it to evolve,Broad Issues to

5、 Consider in Design,1. Interface The classes, methods, parameters, names 2. Resource Management How is memory, other resources dealt with 3. Error Handling What errors are caught and what is done Information Hiding How much detail is exposed Impacts all three of the above,1. Interface Principles,Sim

6、ple General Regular Predictable Robust Adaptable,Simple,Users have to understand! Do one thing and do it well Functionality should be easy to explain As small as possible, but never smaller Conceptual weight more important than providing all functionality Avoid long parameter lists Choose small set

7、of orthogonal primitives Dont provide 3 ways to do the same thing,General,Implementation can change, API cant Hide Information! Dont let implementation detail leak into API Minimize accessibility (e.g. private classes and members) Implementation details can confuse users Be aware of what is implemen

8、tation Dont overspecify behavior of modules Tuning parameters are suspect,Regular,Do the same thing the same way everywhere Related things should be achieved by related means Consistent parameter ordering, required inputs Functionality (return types, errors, resource management) Names matter Self ex

9、planatory Consistent across API Same word means same thing in API Same naming style used Consistent with related interfaces outside the API,Predictable,Dont violate the principle of Least Astonishment User should not be surprised by behavior Even if this costs performance Dont reach behind the users

10、 back Accessing and modifying global variables Secret files or information written Be careful about static variables,Predictable,Try to minimize use of other interfaces Make as self-contained as possible Be explicit about external services required Document! Every class, method, interface, construct

11、or, parameter, exception When states are kept, this should be very clearly documented,Robust,Able to deal with unexpected input Error Handling (see later),Adaptable,API can be extended, but never shortened Heavily used APIs likely will be extended Information Hiding Implementation details should not

12、 affect API,2. Resource Management,Determine which side is responsible for Initialization Maintaining state Sharing and copying Cleaning up Various resources Memory Files Global variables,Resource Management,Generally, free resources where they were allocated Return references or copies? Can have hu

13、ge performance and ease of use impact Multi-threaded code makes this especially critical Reentrant: works regardless of number of simultaneous executions Avoid using anything (globals, static locals, other modifications) that others could also use Locks can be important,3. Error Handling,Catch error

14、s, dont ignore them “Print message and fail” is not always good Especially in APIs Need to allow programs to recover or save data Detect at low level, but handle at high level Generally, error should be handled by calling routine The callee can leave things in a “nice” state for recovery, though Kee

15、p things usable in case the caller can recover,Fail Fast,Report as soon as an error occurs Sometimes even at compile time! Use of static types, generics,Error Management,Return values Should be in form the calling function can use Return as much useful information as possible Sentinel values only wo

16、rk if function cannot return all possible values of that type Define pairs, or return another parameter to indicate errors Use error “wrapper function” if needed Consistent way of marking, reporting error status Encourages use But, can add complexity,Exceptions,Generally indicate a programming error

17、 Programming construct Set exception value (e.g. as return) Other program operation when exception thrown Exceptions usually in global registry Include information about failure For repair and debugging Exceptions should generally be unchecked Automatically process globally, rather than require explicit checks over and over,Exceptions,Only use in truly exceptional situations Never use as a control structure The modern GOTO Never use exceptions for expected return values e.g. Invalid file name passed to library is “common”, not an exception,

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1