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
- 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.
- AspectJ Team, The. The AspectJ Programming Guide. 2003.
- 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.
- 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.
- Duncan, A., and Hölzle, U. Adding Contracts to Java with Handshake. Technical report TRCS98-32, December 8, 1998.
- Ecma. Eiffel: Analysis, Design and Programming Language (2nd ed.), June 2006.
- Findler, R., and Felleisen, M. Contract Soundness for Object-Oriented Languages. Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA), Florida, USA, 2001.
- First Person Inc. Oak Language Specification. 1994.
- Gosling, J., Joy, B., Steele, G., and Bracha, G. The Java Language Specification (3rd edition). Prentice-Hall, 2005.
- Guerreiro, P. Simple Support for Design by Contract in C++, TOOLS USA 2001, Proceedings, pages 24-34, IEEE, 2001.
- Hoare, C. An Axiomatic Basis for Computer Programming. Communications of the ACM, Vol. 12, No. 10, October 1969.
- 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.
- Kramer, R. iContract - the Java design by contract tool. 26th Technology of ObjectOriented Languages and Systems (TOOLS), California, USA, 1998.
- Laddad, R. AspectJ in Action: Pratical Aspect-Oriented Programming. Manning, 2003.
- Lindholm, T., and Yellin, F. The Java Virtual Machine Specification. Prentice-Hall, 1999.
- Liskov, B., and Wing, J. Family Values: A Behavioral Notion of Subtyping. Technical report MIT/LCS/TR-562b, Carnegie Mellon University, July 16, 1993.
- Meyer, B. Eiffel: The Language. Prentice-Hall, 1991.
- Meyer, B. Object-Oriented Software Construction (2nd ed.). Prentice-Hall, 1997.
- Mitchell, R., and McKim, J. Design by Contract, by Example. Addison-Wesley, 2002.
- OMG Unified Modeling Language (UML) 2.0 OCL convenience document. 2005.
- 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.
- Rieken, J. Design by Contract for Java - Revised (master thesis), Carl von Ossietzky Universität - Correct System Design Group, April 24th, 2007.
- Sun Microsystems Java 2 Platform Standard Edition 5.0 API Specification. 2004.
- 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.
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