How to design API Summary "C ++ API design."

Many software engineers prefer to API abbreviated Abstract Programming Interfaces instead of Application Programming Interfaces.

API header files and contains more relevant supporting documents in c ++

Interface is the most important code written by the developer, problems related to the implementation code than larger fix problems arise interfaces price.

API for programmers developed the user interface, you can be called an API you ever thought about the way

Must ensure backward compatibility when modified API

API life cycle is longer, in order to create a good pre-API requires a relatively large cost. Therefore the planning, design, edition, review than the essential, the latter significantly reduce long-term costs, updates to achieve improvements will not affect customers

When writing API, good documentation is essential, especially in the case do not provide the source code.

Automated testing is also very important, tens of thousands of other developers rely on the correctness of your code when the API changes, a complete regression testing to ensure that customers have more confidence in Ben's program does not collapse.

The benefits of API

1. hide implementation: implementation details by hiding inside, developers can modify the code to achieve future freedom, does not give the user a significant impact

2. extend the life: over time, the code that implements those disclosed internal details will become complicated, the other parts of the system depends on the further implementation details, the system will become fragile, rigid, intractable and high viscosity Timor Therefore pre-designed API, the latter can ensure the consistency of the software life expectancy

3. Modular promote: API typically perform specific tasks and use cases. API defines a set of modular feature set, a large number of applications developed with the API coupling reduced, promotes modularity.

4. Repeat reduce code: After all of the logic through the interface in the interface, a behavior unitary program will help to eliminate the code duplication.

The elimination of hard-coded assumptions: that contains a lot of hard-coded values, and continue to replicate,

6. easy to change the implementation:

7. Ease of optimization: do not hide the implementation details, while optimizing code regardless of the client's call

 

Convenient API: Simplified API is a difficult thing to reduce the API function and a variety of easy-to-client API exists a natural contradiction between use

Progressive public, API presents the basic functionality through easy to use interface, while the advanced features hidden to another independent hierarchy.

 

Ease of use: good API design should make simple tasks easier, it makes clear. Good API allows customers aware of its signature method of use, without the need for a document. Follow the smallest surprise (leaset surprise)

  1. Discoverability: API can be found requires users to understand how they are used by the API itself, without any explanation and documentation.

  2. misuse is not easy: not nearly good API is easy to use, but also easy to misuse, this is the most important principles of universal design interface.

  3. Consistency: good API design methods should be consistent, so keep in mind that style to the user, thus easier user adoption. For example naming conventions, the order parameter, the standard design mode, the internal model semantics, abnormal use, and error handling.

  4. orthogonal: in API design, it has no side effects other than the orthogonal method, the method attribute of a particular method invocation settings should be changed only familiar with this property, without changing the properties of other publicly accessible.

 

Loose coupling:

 

Guess you like

Origin www.cnblogs.com/tianc/p/8783507.html