HP Labs Technical Reports

The Separation of Interface and Implementation in C++

Martin, Bruce E.



Abstract: A C++ class declaration combines the external interface of an object with the implementatin of that interface. It is desirable to be able to write client code that depends only on the external interface of a C++ object and not on its implementation. Althought C++ encapsulation can hide the implementation details of a class from client code, the client must refer to the class name and thus depends on the implied implementation as well as its interface. PP In this paper, we review why separation of interface and implementation is desirable and demonstrate how a separate interface lattice and multiple implementation lattices can be used in C++ programs. We describe minor language extensions that make the distinction between the interface lattice and implementation lattice apparent to the C++ programmer. Implementations are combined using standared C++ multiple inheritance. The operations of an interface are given by the union of operations of its contained interfaces. Variables and parameters are typed by interfaces. We describe how separate interface lattices and implementation lattices are realized in standard C++ code.

Back to Index

[Research] [News] [Tech Reports] [Palo Alto] [Bristol] [Japan] [Israel] [Site Map] [Home] [Hewlett-Packard]