Open cosven opened 7 years ago
参考资料:
Funcitonality should be easy to explain
def strcpy(dest, src)
def bcopy(dest, src, n)
参考资料:
Characteristics of a Good API
The process of API Design
General Principles
API should do one thing and do it well
Funcitonality should be easy to explain
API should be as small as possible but no smaller
Implementation should not impact API
Minimize accessibility of everything
Names matters - API is a little language
Documentation matters
Consider performance consequences of API desing decisions ?
Class Design
Minimize Mutability
Subclass only where is makes sense
Design and document for inheritance or else prohibit it.
Method design
don't make the client do anything the module could do
don't violate the principle of least astonishment
fail fast-report errors as soon as possible after they occur
Provide programmatic access to all data available in string form
use appropriate parameter and return types
use consistent parameter ordering across methods.
def strcpy(dest, src)
def bcopy(dest, src, n)
avoid long parameter lists
avoid return values that demand exceptional processing
Exception Design
Throw exceptions to indicate exceptional conditions
Favor unchecked exceptions
include failure-capture information in exceptions
Refactoring API Designs