If you can't read please download the document
Upload
imyousuf
View
2.534
Download
0
Embed Size (px)
DESCRIPTION
This is a presentation inspired (heavily) by that of Joshu Bloch's presentation on "How to design a good API and its importance". I tried to simplify on API importance and tried to generify how to conceive it. No point referring to that presentation explicitly as I am mentioning it here and mentioned it at the start and end of the presentation as I made it in BASIS SoftExpo 2012
Citation preview
2. Outline
3. Why is API important? 4. Designing API 5. General Principles 6. OOP Design Principles Smart IT Engineering Ltd. 7. What is an API?
8. API is a source code-basedspecification intended to be used as an interface bysoftware components to communicatewith each other. 9. ABI (Application Binary Interface) differs to API in that the former is specified on binary interface 10. In this presentation we will consider ABI as API too Smart IT Engineering Ltd. 11. Why is API important?
12. Do we integrate Facebook API (FB Login, Like, Share, etc.)? How? 13. How do we develop softwares that require system level integration? 14. How do Web 2.0 portals communicate with its server? 15. How do Smart Phone / Tablet Apps communicate with server? Smart IT Engineering Ltd. 16. Why is API important?
17. A lot of (Almost all) websites integrate with FB using its JavaScript API 18. For Windows we use MFC or Windows API; for *nix system we use POSIX etc. 19. Web 2.0 / Smart Phone / Tablet Apps make server side calls via HTTP protocol either from a App or from browser using AJAX. Smart IT Engineering Ltd. 20. Why is API important?
Smart IT Engineering Ltd. 21. Why is API important?
22. You are developing an Android or iPhone App and having problem using their API as you not understanding how to simply achieve them. What would you do? 23. Your client asked you to use a Web Service to integrate one service to another and the Web Service makes no sense what so over and furthermore, it does not have ample documentation. What would you do? 24. What would be your opinion of such API providers? Smart IT Engineering Ltd. 25. Why is API important?
26. Contact Andoid community mailing lists/forums and ask there 27. Contact iPhone Developer Community and ask there 28. Ask my customer to get me documentation or ask the company/developer for help 29. We think those companies and their developers are crap and we are better than them Smart IT Engineering Ltd. 30. Why is API important?
31. API can be among a company's greatest assets
32. Cost to stop/change API can be prohibitive 33. Successfully Public APIs capture customers Bad API causes unending support request and becoming a liability to the company Smart IT Engineering Ltd. 34. Why is API important?
Useful modules tend to get reused
35. Good reusable modules are corporate assets Thinking in terms of APIs improves code quality Smart IT Engineering Ltd. 36. Characteristics of a Good API
37. Easy to use, even without documentation 38. Hard to misuse 39. Easy to read and maintain code that uses it 40. Sufficiently powerful to satisfy requirements 41. Easy to extend 42. Appropriate to audience Smart IT Engineering Ltd. 43. Designing API Smart IT Engineering Ltd. 44. Gather Requirements
We must extract true requirements in form ofuse-cases . 45. Can be easier and more rewarding to build something more general
Smart IT Engineering Ltd. 46. Start with short spec
47. At the very beginning agility trumps completeness 48. Bounce spec off as many head as possible
Once confidence is there that we understand what it is grow the spec
Smart IT Engineering Ltd. 49. Write it early & often
50. Thus saving implementing something that is not useful API code helps you show the spec itself
Continue writing to API Smart IT Engineering Ltd. 51. Write an SPI
52. It serves as an API used by API implementations 53. For example, Data Access Layer implementations Write multiple SPI implementations before release
54. If you write one, it probably won't support another 55. If you write two, it will support more with difficulty 56. If you write three, it will work fine Smart IT Engineering Ltd. 57. Maintain Realistic Expectation
58. Aim to displease everyone equally 59. Stick to what you want to achieve Expect to make mistakes
60. Expect to evolve API Smart IT Engineering Ltd. 61. General Principles Smart IT Engineering Ltd. 62. Should Do One Thing & Do It Well
63. Good names enables API to thrive 64. Be open to splitting and merging modules Functionality should be well specified
65. Write tests demonstrating API usage 66. Specification will get more specific through usage Smart IT Engineering Ltd. 67. Keep it Small but No Smaller
68. When in doubt leave it out
Conceptual weight more important than bulk
Look for a power-to-weight ratio
Smart IT Engineering Ltd. 69. Implementation shouldn't impact API
70. Inhibit freedom to change implementation Be aware of what is an implementation detail
Don't let implementation details leak into API
Smart IT Engineering Ltd. 71. Minimize Accessibility of Everything
72. Public class should have no public fields other than constants 73. This maximizes information hiding 74. Allows modules to be used, understood, built, tested and debugged independently Smart IT Engineering Ltd. 75. Names Matter API is a Language
Be consistent Same word means same thing 76. Be regular strive for symmetry 77. Code should read like prose Smart IT Engineering Ltd. 78. Documentation Matters
Smart IT Engineering Ltd. 79. Document Religiously
80. Method: Contract between method and its client
Document state space very carefully Smart IT Engineering Ltd. 81. Performance Consequence
82. Do not wrap API to gain performance 83. Be aware of stateful vs stateless requirements Smart IT Engineering Ltd. 84.
Smart IT Engineering Ltd. 85. Class Design
86. If mutable keep state space small, well-defined Subclass only where it makes sense
87. Prefer composition over inheritence 88. Bad example of inheritance is Properties of Java Document for inheritance else prohibit it Smart IT Engineering Ltd. 89. Method Design
Don't violate the principle of least astonishment
Fail Fast report errors as soon as possible 90. Provide programmatic access to all data available in string form to avoid user parsing strings Smart IT Engineering Ltd. 91. Method Design
92. Just because you can doesn't mean you should Use appropriate parameter and return types
93. Use most specific possible input parameter type 94. Avoid using float (32 bits) in favor of double (64 bits) Smart IT Engineering Ltd. 95. Method Design
96. Avoid long parameter list
97. Lon list of identically typed params is harmful 98. Break up methods or create helper class to hold parameters Avoid return values that demand exceptional processing
Smart IT Engineering Ltd. 99. Exception Design
100. Conversely, don't fail silently Favor unchecked exceptions
101. Unchecked Programming error Include failure capture information in exceptions Smart IT Engineering Ltd. 102. Conclusion
103. This presentation covered some heuristics of the craft 104. API design is tough 105. Once a API is Public it can evolve but has to support earlier releases Smart IT Engineering Ltd. 106. Questions? Smart IT Engineering Ltd.