API Design for C++
eBook - ePub

API Design for C++

Martin Reddy

  1. 472 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

API Design for C++

Martin Reddy

Book details
Book preview
Table of contents
Citations

About This Book

API Design for C++ provides a comprehensive discussion of Application Programming Interface (API) development, from initial design through implementation, testing, documentation, release, versioning, maintenance, and deprecation. It is the only book that teaches the strategies of C++ API development, including interface design, versioning, scripting, and plug-in extensibility. Drawing from the author's experience on large scale, collaborative software projects, the text offers practical techniques of API design that produce robust code for the long term. It presents patterns and practices that provide real value to individual developers as well as organizations. API Design for C++ explores often overlooked issues, both technical and non-technical, contributing to successful design decisions that product high quality, robust, and long-lived APIs. It focuses on various API styles and patterns that will allow you to produce elegant and durable libraries. A discussion on testing strategies concentrates on automated API testing techniques rather than attempting to include end-user application testing techniques such as GUI testing, system testing, or manual testing. Each concept is illustrated with extensive C++ code examples, and fully functional examples and working source code for experimentation are available online. This book will be helpful to new programmers who understand the fundamentals of C++ and who want to advance their design skills, as well as to senior engineers and software architects seeking to gain new expertise to complement their existing talents. Three specific groups of readers are targeted: practicing software engineers and architects, technical managers, and students and educators.

  • The only book that teaches the strategies of C++ API development, including design, versioning, documentation, testing, scripting, and extensibility
  • Extensive code examples illustrate each concept, with fully functional examples and working source code for experimentation available online
  • Covers various API styles and patterns with a focus on practical and efficient designs for large-scale long-term projects

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is API Design for C++ an online PDF/ePUB?
Yes, you can access API Design for C++ by Martin Reddy in PDF and/or ePUB format, as well as other popular books in Ciencia de la computación & Programación. We have over one million books available in our catalogue for you to explore.

Information

Year
2011
ISBN
9780123850041
Chapter 1

Introduction

Publisher Summary

This chapter defines an Application Programming Interface (API), which provides an abstraction for a problem and specifies how clients should interact with software components that implement a solution to that problem. API development is ubiquitous in modern software development. Its purpose is to provide a logical interface to the functionality of a component while also hiding any implementation details. It can be as small as a single function or involve hundreds of classes, methods, free functions, data types, enumerations, and constants. Its implementation can be proprietary or open source. The important underlying concept is that an API is a well-defined interface that provides a specific service to other pieces of software. An API is an interface designed for developers, in much the same way that a Graphical User Interface (GUI) is an interface designed for end users.
Defines what an Application Programming Interface (API) is with various examples and describes how an API is represented in C++. This chapter details the difference between API development and standard application development, as well as enumerating the pros and cons of APIs in software development. I then illustrate the various layers of APIs that a modern application is built on, with specific reference to a large open source client/server program. The relationship of the terms API and SDK is explained, as is the relationship among APIs, file formats, and network protocols.

1.1 What are Application Programming Interfaces?

An Application Programming Interface (API) provides an abstraction for a problem and specifies how clients should interact with software components that implement a solution to that problem. The components themselves are typically distributed as a software library, allowing them to be used in multiple applications. In essence, APIs define reusable building blocks that allow modular pieces of functionality to be incorporated into end-user applications.
An API can be written for yourself, for other engineers in your organization, or for the development community at large. It can be as small as a single function or involve hundreds of classes, methods, free functions, data types, enumerations, and constants. Its implementation can be proprietary or open source. The important underlying concept is that an API is a well-defined interface that provides a specific service to other pieces of software.
A modern application is typically built on top of many APIs, where some of these can also depend on further APIs. This is illustrated in Figure 1.1, which shows an example application that depends directly on the API for three libraries (1–3), where two of those APIs depend on the API for a further two libraries (4 and 5). For instance, an image viewing application may use an API for loading GIF images, and that API may itself be built upon a lower-level API for compressing and decompressing data.
image

Figure 1.1 An application that calls routines from a hierarchy of APIs. Each box represents a software library where the dark section represents the public interface, or API, for that library, while the white section represents the hidden implementation behind that API.
API development is ubiquitous in modern software development. Its purpose is to provide a logical interface to the functionality of a component while also hiding any implementation details. For example, our API for loading GIF images may simply provide a LoadImage() method that accepts a filename and returns a 2D array of pixels. All of the file format and data compression details are hidden behind this simple interface. This concept is also illustrated in Figure 1.1, where client code only accesses an API via its public interface, shown as the dark section at the top of each box.

1.1.1 Contracts and Contractors

As an analogy, consider the task of building your own home. If you were to build a house entirely on your own, you would need to possess a thorough understanding of architecture, plumbing, electronics, carpentry, masonry, and many other trades. You would also need to perform every task yourself and keep track of the minutest of details for every aspect of the project, such as whether you have enough wood for your floorboards or whether you have the right fasteners to fit the screws that you've bought. Finally, because you are the only person working on the project, you can only perform a single task at any point in time and hence the total time to complete the project could be very large.
An alternative strategy is to hire professional contractors to perform key tasks for you (Figure 1.2). You could hire an architect to design the plans for the house, a carpenter for all of your woodwork needs, a plumber to install the water pipes and sewage system for your house, and an electrician to set up the power systems. Taking this approach, you negotiate a contract with each of your contractors—telling them what work you want done and agreeing upon a price—they then perform that work for you. If you're lucky, maybe you even have a good friend who is a contractor and he offers you his services for free. With this strategy, you are freed from the need to know everything about all aspects of building a house and instead you can take a higher-level supervisory role to select the best contractors for your purpose and ensure that the work of each individual contractor is assembled together to produce the vision of your ideal home.
image

Figure 1.2 Using contractors to perform specialized tasks to build a house.
The analogy to APIs is probably obvious: the house that you're building equates to a software program that you want to write, and the contractors provide APIs that abstract each of the tasks you need to perform and hide the implementation details of the work involved. Your task then resolves to selecting the appropriate APIs for your application and integrating them into your software. The analogy of having skilled friends who provide contracting services for free is meant to represent the use of freely available open source libraries in contrast to commercial libraries that require a licensing fee to use in your software. The analogy could even be extended by having some of the contractors employing subcontractors, which corresponds to certain APIs depending on other APIs to perform their task.
The contractor analogy is a common one in object-oriented programming. Early practitioners in the field talked about an object defining a binding contract for the services or behavior that it provides. An object then implements those services when asked to by a client program, potentially by subcontracting some of the work out to other objects behind the scenes (Meyer, 1987; Snyder, 1986).

1.1.2 APIs in C++

Strictly speaking, an API is simply a description of how to interact with a component. That is, it provides an abstraction and a functional specification for a component. In fact, many software engineers prefer to expand the acronym API as Abstract Programming Interface instead of Application Programming Interface.
In C++, this is embodied as one or more header (.h) files plus supporting documentation files. An implementation for a given API is often represented as a library file that can be linked into end-user applications. This can be either a static library, such as a .lib file on Windows or .a on Mac OS X and Linux, or a dynamic library such as a .dll file on Windows, .dylib on Mac, or .so on Linux.
A C++ API will therefore generally include the following elements:
1. Headers: A collection of .h header files that define the interface and allow client code to be compiled against that interface. Open source API...

Table of contents