Chapter 12. Supporting AOP Using ReflectionNOURY BOURAQADI AND THOMAS LEDOUX Aspect-oriented programming (AOP) allows applications to be developed by implementing crosscutting concerns (i.e., aspects) in a loosely coupled fashion [27]. The application results from a weaving process that knits aspects with core functionalities (i.e., base code). This weaving is done at join points, which are points within the base code execution flow [16]. Isolating aspects and weaving them with base code are two critical issues of the AOP paradigm. One possible approach for implementing these mechanisms is reflection. Reflection is the ability of a system to observe and change its own execution [29, 36]. In an object-oriented reflective programming language, this is made possible by representing program entities (e.g., classes, methods) and execution mechanisms (e.g., interpreter, garbage collector) as full-fledged meta-objects. Since meta-objects control the execution of base objects (i.e., plain objects), a change in a meta-object alters program behavior. This control is done through an explicit link between base and meta-objects, the meta-link. This chapter explores the relationship between reflection and AOP. The duality between base and meta-objects and their connection through the meta-link makes reflection a natural solution for supporting AOP. Separation is achieved by making base objects represent base code and meta-objects represent aspect code. Weaving relies on the meta-link that connects base objects (and then base code) to meta-objects (and then aspect code). In this context, Meta-Objects Protocols (MOP) support join points. The chapter is organized as follows. In Section 12.1, we present reflection, emphasizing that reflective systems are structured into layers (meta-levels). This presentation also covers the concepts of meta-objects, MOP, and meta-link. To illustrate these concepts, we provide a reflective programming language, MetaclassTalk,[1] and present examples of its use. In Section 12.2, we show the capability of reflection to support AOP. More precisely, we demonstrate that aspects can be represented using meta-objects. We also show that aspect weaving in this context relies on the meta-link and meta-object composition. In Section 12.3, we discuss the advantages and drawbacks of using reflection for AOP. Section 12.4 ends the chapter with a discussion of open issues.
|