This work has been partially supported by the MIUR project EOS-DUE. We present a language extension, which integrates in a Java like language a mechanism for dynamically extending object behaviors without changing their type. Our approach consists in moving the addition of new features from class (static) level to object (dynamic) level: the basic features of entities (representing their structure) are separated from the additional ones (wrapper classes whose instances represent run-time added behaviors). At run-time, these entities can be dynamically composed by instantiating wrapper objects which are attached to basic entities. Wrappers permit specializing (wrapping) methods at run-time: the method of the wrapper will be automatically executed after the method of the wrapped objects, using a delegation mechanism. Furthermore, wrapped methods can return values and values returned by the wrapped methods are transparently made available in the wrapper methods. We formalize our extension by adding the new constructs to Featherweight Java and we prove that the core language so extended (Featherweight Wrap Java) is type safe.
Note: Due to the typographical sophistication of this article, no HTML version is available. Please use the PDF version.
About the authors
Cite this article as follows: Lorenzo Bettini, Sara Capecchi, Elena Giachino: "Featherweight Wrap Java: wrapping objects and methods", in Journal of Object Technology, vol. 7, no. 2, Special Issue OOPS Track at SAC 2007, February 2008, pp. 5-29, http://www.jot.fm/issues/issue_2008_02/article1/