Book: API Design for C++
Publisher: Morgan Kaufmann
Writing large applications in C++ is a complex and tricky business. However, designing reusable C++
interfaces that are robust, stable, easy to use, and durable is even more difficult. The best way to succeed
in this endeavor is to adhere to the tenets of good Application Programming Interface (API)
An API presents a logical interface to a software component and hides the internal details
required to implement that component. It offers a high-level abstraction for a module and promotes
code reuse by allowing multiple applications to share the same functionality.
Modern software development has become highly dependent on APIs, from low-level application
frameworks to data format APIs and graphical user interface (GUI) frameworks. In fact, common
software engineering terms such as modular development, code reuse, componentization, dynamic
link library or DLL, software frameworks, distributed computing, and service-oriented architecture
all imply the need for strong API design skills.
Some popular C and C++ APIs that you may already be aware of include the Standard Template
Library (STL), Boost, the Microsoft Windows API (Win32), Microsoft Foundation Classes (MFC),
libtiff, libpng, zlib, libxml++, OpenGL, MySQL++, Trolltech’s Qt, wxWidgets, GTK+, KDE, SkypeKit,
POSIX pthreads, Intel’s Threading Building Blocks, the Netscape Plugin API, and the
Apache module API. In addition, many of Google’s open-source projects are C++, as is much of
the code on the sourceforge.net, bitbucket.org, and freshmeat.net Web sites.
APIs such as these are used in all facets of software development, from desktop applications, to
mobile computing and embedded systems, to Web development. For example, the Mozilla Firefox
Web browser is built on top of more than 80 dynamic libraries, each of which provides the implementation
for one or more APIs.
Elegant and robust API design is therefore a critical aspect of contemporary software development.
One important way in which this differs from standard application development is the far
greater need for change management. As we all know, change is an inevitable factor in software
development; new requirements, feature requests, and bug fixes cause software to evolve in ways
that were never anticipated when it was first devised. However, changes to an API that is shared
by hundreds of end-user applications can cause major upheaval and ultimately may cause clients
to abandon an API. The primary goal of good API design is therefore to provide your clients with the
functionality they need while also causing minimal impact to their code—ideally zero impact—when
you release a new version.