Ten principles of excellent API design-brother even it education

Source: Internet
Author: User
Tags learn php
Ten principles of excellent API design-brother even it education
Each software developer uses the API. "Good" API design is like magic. However, I don't know how many people can explain why some APIs are complex and difficult to learn, while others are clean, simple, and enjoyable to use. I will answer this question in the article and provide 10 rules for good API design.
1. Just do what you need today
This is the top-level rule. Solve only the problems that must be solved today and minimize the answers that need to be done. The temptation to solve tomorrow's problems is immense. But be sure to resist the temptation! Don't release code in advance, focus on narrowing the release cycle. If it takes a couple of hours to answer a new question, you don't have to guess what will happen tomorrow.
2.API Modular
Turn large-scale issues into smaller, individually-resolved issues. Modular APIs are easier to learn and can change over time. You can replace the old module with the new module. Can teach a module one by one. You can also separate the experimental portions of the API from the stable or traditional sections.
3. Using structured syntax
Use structured API syntax: replace do_action_with_thing with Thing.action or Thing.property. The syntax will naturally adapt to the modular approach, where each module is a class.
4. Using natural semantics
Don't invent new concepts. Use only the well-known concepts of developers as the basis for class systems. If you find yourself needing to explain the concept, it means that you are wrong: either you are solving the problem later, or you are building the API in a wrong way.
5.API Self-agreement
Each class must strictly use the same style and conventions. Consistency means that when a person learns this class, he is able to master all the classes in mastery. Documented conventions that make them the standard that contributors must.
Scalability of 6.API
Scalability has many benefits and is not just welcomed by contributors. It also allows you to delay the implementation because "it is convenient to add it back if needed". Unwanted features are not added, which is also a win.
7. Full Test
Each class and method must undergo a full test of malicious code. Write Tests as you write code, and then use the tests as the API provides to outside contract documents. Run these tests whenever the code changes. Don't worry about code coverage. The important thing is the external conventions. You can also consider using the contract life cycle.
8. Tiered growth
Keep the API focused and then layer the new API at the top so that they can grow over time. Scalability does not imply an indefinite growth. Define the scope of the API and execute it within the scope.
9. Keep it simple and easy to use
The final test depends on how easy it is to use the API. Can you make your code look simpler with the example you wrote? Are you forcing users to explain the options they don't care about? Are there any extra steps that are worthless? Be focused on reducing the viewable area of the API.
10. Keep Portability
Don't let the system concept leak into the API. Neat purposefully Abstract: This API can be run on any operating system. The API must be able to hide the implementation, but be aware of the 4th rule and the use of natural abstraction.
Free to receive the lamp brother even original PHP video tutorial CD/"Detailed PHP" Essentials Edition, details of the website customer service:
Http://www.lampbrother.net
"Brother Even it education" learn PHP, Linux, HTML5, UI, Android and other video tutorials (Courseware + notes + video)!
Web Drive Tutorial Download: http://pan.baidu.com/s/1mg8ANMg

The above introduces the top ten principles of excellent API design-brother even it education, including the content of the aspects, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.