An Aspect for Design by Contract in Java

Sérgio Agostinho, Pedro Guerreiro, Hugo Taborda

2008

Abstract

Several techniques exist for introducing Design by Contract in languages providing no direct support for it, such as Java. One such technique uses aspects that introduce preconditions and postconditions by means of before and after advices. For using this, programmers must be knowledgeable of the aspect language, even if they would rather concentrate on Design by Contract alone. On the other hand, we can use aspects to weave in preconditions, preconditions and invariants that have been programmed in the source language, as regular Boolean functions. In doing this, we must find ways to automatically “inherit” preconditions and postconditions when redefining functions in subclasses and we must be able to record the initial state of the object when calling a modifier, so that it can be observed in the postconditions. With such a system, during development, the program will be compiled together with the aspects providing the Design by Contract facilities, using the compiler for the aspect language, and the running program will automatically check all the weaved in assertions, raising an exception when they evaluate to false. For the release build, it suffices to compile using the source language compiler, ignoring the aspects, and the assertions will be left out.

References

  1. Abrial, J., Schuman, S., and Meyer, B. A Specification Language. On the Construction of Programs, Cambridge University Press, McNaughten, R., and McKeag, R. (editors), 1980.
  2. AspectJ Team, The. The AspectJ Programming Guide. 2003.
  3. Balzer, S., Eugster, P., and Meyer, B. Can Aspects Implement Contracts? Proceedings of Rapid Integration of Software Engineering techniques (RISE), Geneva, Switzerland, September 13-15, 2006.
  4. Burdy, L., Cheon, Y., Cok, D., et al. An overview of JML tools and applications. International Journal on Software Tools for Technology Transfer, June 2005.
  5. Duncan, A., and Hölzle, U. Adding Contracts to Java with Handshake. Technical report TRCS98-32, December 8, 1998.
  6. Ecma. Eiffel: Analysis, Design and Programming Language (2nd ed.), June 2006.
  7. Findler, R., and Felleisen, M. Contract Soundness for Object-Oriented Languages. Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA), Florida, USA, 2001.
  8. First Person Inc. Oak Language Specification. 1994.
  9. Gosling, J., Joy, B., Steele, G., and Bracha, G. The Java Language Specification (3rd edition). Prentice-Hall, 2005.
  10. Guerreiro, P. Simple Support for Design by Contract in C++, TOOLS USA 2001, Proceedings, pages 24-34, IEEE, 2001.
  11. Hoare, C. An Axiomatic Basis for Computer Programming. Communications of the ACM, Vol. 12, No. 10, October 1969.
  12. Karaorman, M., and Abercrombie, P. jContractor: Introducing Design-by-Contract to Java Using Reflective Bytecode Instrumentation. Formal Methods in System Design, Vol. 27, No. 3, November, 2005.
  13. Kramer, R. iContract - the Java design by contract tool. 26th Technology of ObjectOriented Languages and Systems (TOOLS), California, USA, 1998.
  14. Laddad, R. AspectJ in Action: Pratical Aspect-Oriented Programming. Manning, 2003.
  15. Lindholm, T., and Yellin, F. The Java Virtual Machine Specification. Prentice-Hall, 1999.
  16. Liskov, B., and Wing, J. Family Values: A Behavioral Notion of Subtyping. Technical report MIT/LCS/TR-562b, Carnegie Mellon University, July 16, 1993.
  17. Meyer, B. Eiffel: The Language. Prentice-Hall, 1991.
  18. Meyer, B. Object-Oriented Software Construction (2nd ed.). Prentice-Hall, 1997.
  19. Mitchell, R., and McKim, J. Design by Contract, by Example. Addison-Wesley, 2002.
  20. OMG Unified Modeling Language (UML) 2.0 OCL convenience document. 2005.
  21. Plösh, R. Evaluation of Assertion Support for the Java Programming Language. Journal of Object Technology, Vol. 1, No. 3, Special Issue: TOOLS USA 2002 proceedings.
  22. Rieken, J. Design by Contract for Java - Revised (master thesis), Carl von Ossietzky Universität - Correct System Design Group, April 24th, 2007.
  23. Sun Microsystems Java 2 Platform Standard Edition 5.0 API Specification. 2004.
  24. Wampler, D. Contract4J for Design by Contract in Java: Designing Pattern-Like Protocols and Aspect Interfaces. Industry Track at AOSD 2006, Bonn, Germany, March 22, 2006.
Download


Paper Citation


in Harvard Style

Agostinho S., Guerreiro P. and Taborda H. (2008). An Aspect for Design by Contract in Java . In Proceedings of the 6th International Workshop on Modelling, Simulation, Verification and Validation of Enterprise Information Systems - Volume 1: MSVVEIS, (ICEIS 2008) ISBN 978-989-8111-43-2, pages 119-128. DOI: 10.5220/0001743001190128


in Bibtex Style

@conference{msvveis08,
author={Sérgio Agostinho and Pedro Guerreiro and Hugo Taborda},
title={An Aspect for Design by Contract in Java},
booktitle={Proceedings of the 6th International Workshop on Modelling, Simulation, Verification and Validation of Enterprise Information Systems - Volume 1: MSVVEIS, (ICEIS 2008)},
year={2008},
pages={119-128},
publisher={SciTePress},
organization={INSTICC},
doi={10.5220/0001743001190128},
isbn={978-989-8111-43-2},
}


in EndNote Style

TY - CONF
JO - Proceedings of the 6th International Workshop on Modelling, Simulation, Verification and Validation of Enterprise Information Systems - Volume 1: MSVVEIS, (ICEIS 2008)
TI - An Aspect for Design by Contract in Java
SN - 978-989-8111-43-2
AU - Agostinho S.
AU - Guerreiro P.
AU - Taborda H.
PY - 2008
SP - 119
EP - 128
DO - 10.5220/0001743001190128