SDK development basic specifications

Easy to call

  • SDK integration cost
  • Easy to call
  • Function can be customized
  • Function can be extended
  • Easy to debug

API interface design

  • Interface naming, parameter name specification
    • The naming (method name, parameters) is clear and unambiguous. It is better to have a long name and not have words that do not express the meaning, for example: name and userName,
    • The common name should be unified, for example: userId and userID and mUserID;
    • Abbreviations can be avoided as much as possible
  • Try to do only one thing for an interface
    • Clearly organized
    • The caller may use different combinations later
  • Parameter design
    • Some fixed parameters can be set when the SDK is initialized through the config configuration parameters
    • Minimal interface parameters
      • Too many parameters, can be combined into one object
  • It can be called synchronously as much as possible, and the result can be returned without callback. Don't use callback
  • Multithreading can handle it by itself

High performance

  • Memory usage, memory jitter
  • Multi-threaded control to avoid blocking of the main thread
  • Power consumption

Callback design

  • Reduce global callbacks; if global callbacks are necessary, sub-module callbacks
  • There are as few interfaces as possible in the callback
  • Abnormal situation callback
    • Error callback adopts the combination of errorCode+errorMsg

Log design

  • Core processing log
  • The log log can be configured, and the log level can be controlled

Stability, handle exceptions autonomously

  • First go to verify the correctness of the parameters

Code comments should be standardized and clear

  • Interface annotations should be particularly perfect
  • Annotation

Help document, refer to github high star project

  • How to access
  • how to use
  • Version update record

note

  • TODO writing method: TODO person in charge information
  • Backward compatible
  • Resource file naming
    • Use uniform prefix, and can distinguish modules
    • This not only facilitates the resource differentiation of different modules, but also prevents resource conflicts.

Guess you like

Origin blog.csdn.net/terrychinaz/article/details/114122948