This Article 
 Bibliographic References 
 Add to: 
Contract-Checking Wrappers for C++ Classes
November 2004 (vol. 30 no. 11)
pp. 794-810
Two kinds of interface contract violations can occur in component-based software: A client component can fail to satisfy a requirement of a component it is using, or a component implementation can fail to fulfill its obligations to the client. The traditional approach to detecting and reporting such violations is to embed assertion checks into component source code, with compile-time control over whether they are enabled. This works well for the original component developers, but it fails to meet the needs of component clients who do not have access to source code for such components. A wrapper-based approach, in which contract checking is not hard-coded into the underlying component but is "layered” on top of it, offers several relative advantages. It is practical and effective for C++ classes. Checking code can be distributed in binary form along with the underlying component, it can be installed or removed without requiring recompilation of either the underlying component or the client code, it can be selectively enabled or disabled by the component client on a per-component basis, and it does not require the client to have access to any special tools (which might have been used by the component developer) to support wrapper installation and control. Experimental evidence indicates that wrappers in C++ impose modest additional overhead compared to inlining assertion checks.

[1] A. Alexandrescu, Modern C++ Design: Generic Programming and Design Patterns Applied. Addison-Wesley, 2001.
[2] V. Batov, “Safe and Economical Reference-Counting in C++ — Smart Pointers Keep Getting Smarter,” C/C++ Users J., vol. 18, no. 6, pp. 44-57, June 2000.
[3] A. Beugnard, J.-M. Jézéquel, and N. Plouzeau, “Making Components Contract Aware,” Computer, vol. 32, no. 7, pp. 38-45, July 1999.
[4] Y. Cheon and G.T. Leavens, “A Runtime Assertion Checker for the Java Modeling Language (JML),” Proc. Int'l Conf. Software Engineering Research and Practice (SERP '02), pp. 322-328, June 2002.
[5] Y. Cheon and G.T. Leavens, “A Simple and Practical Approach to Unit Testing: The JML and JUnit Way,” Proc. 16th European Conf. Object-Oriented Programming, pp. 231-255, 2002.
[6] J.O. Coplien, Advanced C++ Programming Styles and Idioms. Addison-Wesley, 1992.
[7] A. Duncan and U. Hölzle, “Adding Contracts to Java with Handshake,” Technical Report TRCS98-32, Univ. of California at Santa Barbara, Dec. 1998, 1998-32.shtml.
[8] S.H. Edwards, “Representation Inheritance: A Safe Form of `White Box' Code Inheritance,” IEEE Trans. Software Eng., vol. 23, no. 2, pp. 83-92, Feb. 1997.
[9] S. Edwards, G. Shakir, M. Sitaraman, B.W. Weide, and J. Hollingsworth, “A Framework for Detecting Interface Violations in Component-Based Software,” Proc. Fifth Int'l Conf. Software Reuse, pp. 46-55, June 1998.
[10] S.H. Edwards, “Black-Box Testing Using Flowgraphs: An Experimental Assessment of Effectiveness and Automation Potential,” Software Testing, Verification and Reliability, vol. 10, no. 4, pp. 249-262, Dec. 2000.
[11] R.B. Findler, M. Latendresse, and M. Felleisen, “Behavioral Contracts and Behavioral Subtyping,” Proc. Eighth European Software Eng. Conf. and Ninth ACM SIGSOFT Int'l Symp. Foundations of Software Eng., pp. 229-236, 2001.
[12] E. Gamma, R. Helm, R. Johnson, and J. Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, 1995.
[13] C. Gülcü, The Complete Log4j Manual. QOS.CH, 2003.
[14] J.E. Hollingsworth, L. Blankenship, and B.W. Weide, “Experience Report: Using RESOLVE/C++ for Commercial Software,” Proc. ACM SIGSOFT Eighth Int'l Symp. Foundations of Software Eng., pp. 11-19, Nov. 2000.
[15] “iContract Plus-Making iContract Friendly,” iContract home page, http:/, Aug. 2004.
[16] The Java Modeling Language (JML) Home Page, http:/, Aug. 2004.
[17] R. Kramer, “iContract— The Java Design By Contract Tool,” Proc. Conf. Technology of Object-Oriented Languages (TOOLS 26), pp. 295-307, 1998.
[18] G.T. Leavens, A.L. Baker, and C. Ruby, “JML: A Notation for Detailed Design,” Behavioral Specifications of Businesses and Systems, chapter 12, pp. 175-188, 1999.
[19] B. Liskov and J. Guttag, Abstraction and Specification in Program Development. McGraw-Hill, 1986.
[20] B. Meyer, “Applying ‘Design By Contract’,” Computer, vol. 25, no. 10, pp. 40-51, Oct. 1992.
[21] B. Meyer, Object-Oriented Software Construction, second ed. Prentice Hall, 1997.
[22] D.R. Musser, G.J. Derge, and A. Saini, STL Tutorial and Reference Guide, second ed. Addison-Wesley, 2001.
[23] D.L. Parnas, “A Technique for Software Module Specification with Examples,” Comm. ACM, pp. 330-336, May 1972.
[24] D.E. Perry, “The Inscape Environment,” Proc. 11th Int'l Conf. Software Eng., pp. 2-12, May 1989.
[25] R. Plösch, “Evaluation of Assertion Support for the Java Programming Language,” J. Object Technology, vol. 1, no. 3, pp. 5-17, 2002, .
[26] D.S. Rosenblum, “A Practical Approach to Programming with Assertions,” IEEE Trans. Software Eng., vol. 21, no. 1, pp. 19-31, Jan. 1995.
[27] G. Shakir, “A Systematic Generator for Detecting Interface Violations in Component-Based Software,” MS Report, Dept. of Computer Science and Electrical Eng., West Virginia Univ., Morgantown, 1997.
[28] “Special Section: Component-Based Software Engineering Using RESOLVE,” M. Sitaraman and B.W. Weide, eds., ACM SIGSOFT Software Engineering Notes, vol. 19, no. 4, pp. 21-67, Oct. 1994.
[29] B. Stroustrup, The C++ Programming Language. Addison Wesley, 2000.
[30] C. Szyperski, Component Software: Beyond Object-Oriented Programming. Addison-Wesley, 1998.
[31] R.P. Tan and S.H. Edwards, “An Assertion Checking Wrapper Design for Java,” Technical Report #03-11, Dept. of Computer Science, Iowa State Univ., Ames, Iowa, pp. 29-34, Aug. 2003, 2003/papers/full-paperstan-edwards.pdf .
[32] N. Tan, C. Mingins, and D. Abramson, “Design and Implementation of Assertions for the Common Language Infrastructure,” IEE Proc.— Software Eng., vol. 150, no. 5, pp. 329-336, 2003.
[33] P. Vitharana, “Risks and Challenges of Component-Based Software Development,” Comm. ACM, vol. 46, no. 8, pp. 67-72, Aug. 2003.
[34] J.M. Voas, “Quality Time: How Assertions Can Increase Test Effectiveness,” IEEE Software, vol. 14, no. 2, pp. 118-122, Feb. 1997.
[35] J. Voas and L. Kassab, “Using Assertions to Make Untestable Software More Testable,” Software Quality Professional, vol. 1, no. 4 Sept. 1999.
[36] C. Wang and D.R. Musser, “Dynamic Verification of C++ Generic Algorithms,” IEEE Trans. Software Eng., vol. 23, no. 5, pp. 314-323, May 1997.
[37] J.M. Wing, “A Specifier's Introduction to Formal Methods,” Computer, vol. 29, no. 9, pp. 8-24, Sept. 1990.
[38] J.M. Wing, “Using Larch to Specify Avalon/C++ Objects,” IEEE Trans. Software Eng., vol. 16, no. 9, pp. 1076-1088, Sept. 1990.

Index Terms:
Assertion checkers, binary components, design by contract, preconditions, postconditions, class invariants, coding techniques, debugging aids, specification.
Stephen H. Edwards, Murali Sitaraman, Bruce W. Weide, Joseph Hollingsworth, "Contract-Checking Wrappers for C++ Classes," IEEE Transactions on Software Engineering, vol. 30, no. 11, pp. 794-810, Nov. 2004, doi:10.1109/TSE.2004.80
Usage of this product signifies your acceptance of the Terms of Use.