Importance of APIs and Interface Definitions
Explore the significance of APIs, interface definitions, contracts, and style rules in software development. Learn about different kinds of interfaces, the role of preconditions, and the importance of meeting postconditions for reliable software.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
APIs IMPORTANCE & CHANGES OVER TIME
APIs are A formal connection between modules Can be: App to library Peer to peer Client to Server Always a CONTRACT between the two entities Formalized in SDKs, DDKs
Interface: definition An interface of a set of software mechanisms is the description of techniques enabling clients to use these mechanisms. Touch of Class Learning to Program Well with Objects and Contracts Bertrand Meyer http://touch.ethz.ch/ 3
Kinds of interface User interface: when the clients are people GUI: Graphical User Interface Text interfaces, command line interfaces. Program interface: the clients are other software API: Application Program Interface (or: Abstract Program Interface) We ll now study class APIs. 4
Style rule: header comments Don t even think of writing a feature without immediately including a header comment explaining what it s about 5
Contracts A contract is a semantic condition characterizing usage properties of a class or a feature Three principal kinds: Precondition Postcondition Class invariant 6
Precondition Property that a feature imposes on every client: i_th (i: INTEGER): STATION -- The i-th station on this line require not_too_big: i <= count The precondition of i_th not_too_small: i >= 1 A feature with no require clause is always applicable, as if it had require always_OK: True 7
Assertions Condition Assertion tag not_too_small: i >= 1 Assertion 8
Precondition principle A client calling a feature must make sure that the precondition holds before the call A client that calls a feature without satisfying its precondition is faulty (buggy) software. 9
Postconditions Precondition: obligation for clients Postcondition: benefit for clients remove_all_segments -- Remove all stations except the South-West end. ensure only_one_left: count = 1 both_ends_same: south_end = north_end extend (s: STATION ) -- Add s at end of line. ensure new_station_added: i_th (count) = s added_at_north: north_end = s one_more: count = old count + 1 Expression value captured on entry 10
Postcondition principle A feature must make sure that, if its precondition held at the beginning of its execution, its postcondition will hold at the end. A feature that fails to ensure its postcondition is buggy software. 11
Human-Centered Approach The growing number of tools and services that attempt to assist developers often contribute to more noise, clutter, moving parts and complexity Substantial coordination between tools is required to perform simple operations The busywork draws from a finite pool of cognitive resources, and has been shown to result in greater decision fatigue when confronted with problems of greater substance What humans actually need is an interface that matchers their intuition Software engineers spend more time building mental models and checking assumption than actually writing code Human-Centered Approach to Static-Analysis-Driven Developer Tools Ayman Nadeen, GitHub
The importance of APIs The secret to business success - Microsoft (How?) OS Wars (Microsoft/ Apple) What was the big shift? All teams will henceforth expose their data and functionality through service interfaces. Teams must communicate with each other through these interfaces. There will be no other form of inter-process communication allowed: no direct linking, no direct reads of another team s data store, no shared-memory model, no back-doors whatsoever. The only communication allowed is via service interface calls over the network. It doesn t matter what technology they use. All service interfaces, without exception, must be designed from the ground up to be externalizable. That is to say, the team must plan and design to be able to expose the interface to developers in the outside world. No exceptions. Anyone who doesn t do this will be fired. Thank you; have a nice day! Amazon
How an API can benefit your company It s only recently that solely API-focused businesses have become viable. API-first unicorns have emerged, demonstrating that monetising an API can be a big sell. Efficiency: API-based services can increase reusability, significantly reducing operational overhead. Partner networks: APIs provide an automated way for partners to integrate with your data. Community building: Third-party developers can help spread brand awareness and increase audience size. Productise: Companies may productise APIs in their own right as Software-as-a-Service (SaaS). Regulatory: APIs are helping companies meet new data-sharing regulations e.g. Open Banking, GDPR etc. Financial Services CRM Software Online Shopping Platform https://developer.barclays.com/blog/how-an-api-can-benefit-your-company
API fundamentals Some of the lessons Amazon (and everyone else) learned along the way: Support - Support for your teams interface becomes critical Security - Every teams becomes a potential DOS attacker requiring service levels, quotas and throttling Monitoring / QA - Monitoring and QA are interconnected, you will need smart tools for not just telling if something is up and running, but actually delivering the expected results Discovery - Service discovery becomes important. You will need to know what APIs there are, if they are available and where to find them. Testing - Sandbox and debugging is essential for all APIs (http://apievangelist.com/2012/01/12/the-secret-to-amazons-success-internal-apis/)
And now ? Framework APIs The secret to business success Platform APIs - Microsoft (How?) OS Wars (Microsoft/ Apple) What was the big shift? Smart Device APIs - Amazon (Everything is an API) (http://apievangelist.com/2012/01/12/the-secret-to-amazons-success- internal-apis/) Anyone who doesn t do this will be fired. Thank you; have a nice day!
Examples I want to be a seller: Selling Partner API Guide Show me the money: Square API Push me, Pull me Home James!