SPLAT2007 An Interface Mechanism for Encapsulating Weaving in Class-based AOP Naoyasu Ubayashi Akihiro Sakai Tetsuo Tamai (Kyushu Institute of Technology) (Kyushu Institute of Technology) (University of Tokyo) March 12, 2007 1 Today’s my talk The notion of interface is important in module compositions. It is also important in AO weaving. We provide a new interface mechanism Weaving-interface. This introduces a new weaving mechanism based on componentand-connector architecture. 2 Image of our idea weaving I/F weaving I/F weaving I/F Concern Component (class) Concern Component (class) Concern Component (class) connector connector weaving I/F Concern Component (class) Concern weaving by connectors 3 Outline 1. 2. 3. 4. 5. 6. Motivation Weaving-interface & ccJava Example programs Implementation Related work Conclusion 4 1. Motivation 5 Interface in OOP A client of a class has only to be aware of methods exposed by an interface of the class. A class can be modified without being aware of the client if the class does not change the interface. interface client of a class interface component (class) programmer component (class) programmer 6 However, in AOP … It is not necessarily easy for a programmer to understand the overall behavior of a woven program because a weaving modifies the behavior of a method defined in a class. 7 Our approach A programmer who defines a weaving has only to be aware of weavinginterfaces. A programmer of the class can change its implementation without being aware of the client if the class conforms to its weaving-interfaces. Component weaving-interface component (class) programmer Connector Component programmer who connects components component (class) programmer 8 2. Weaving-interface & ccJava 9 Example --- Figure editor interface Shape { public void moveBy(int dx, int dy); } Component class Point implements Shape { int x, y; public int getX() { return x; } public int getY() { return y; } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } public void moveBy(int dx, int dy) { x += dx; y += dy; } } Component class Line implements Shape { Point p1, p2; public Point getP1() { return p1; } public Point getP2() { return p2; } public void setP1(Point p1) { this.p1 = p1; } public void setP2(Point p2) { this.p2 = p2; } public void moveBy(int dx, int dy) { p1.x += dx; p1.y += dy; p2.x += dx; p2.y += dy; } } Component class Display { public static void update() { /* the detail is ommited */ } } compose three concern components - Point - Line - Display 10 AO weaving based on component-connector architecture export program points (update) wDisplay wPoint class Display wLine class Point Component redraw logging wLogging class Line import program points (at set*, moveBy) Connector class Logging Weaving-interface 11 ccJava: Class-based Crosscutting language for Java ccJava --- a language for supporting weaving-interfaces public w_interface wPoint { Weaving-interface pointcut change(): execution(void setX(int)) || execution(void setY(int)) || execution(void moveBy(int, int)); import before(), after() returning, around() : change(); } public w_interface wLine { pointcut change(): execution(void setP1(Point)) || execution(void setP2(Point)) || execution(void moveBy(int, int)); import before(), after() returning, around() : change(); } A class must implement methods or fields related exposed by pointcuts. Only the program points selected by pointcuts are target of weaving. public w_interface wDisplay { pointcut redraw(): execution(void update()); import before(), after() returning : redraw(); Connector export redraw(); weave { } class Pointimplements wPoint; class Line implements wLine; class Display implements wDisplay; connect(port1:wDisplay.redraw, port2:{wPoint || wLine}.change) { after() returning : port2 { port1.proceed(); } 12 } 3. Example programs 13 Example (1) --- Method composition Weaving-interface public w_interface wColor { pointcut change() : execution(void setColor(int)); export change(); } public w_interface wPoint { pointcut change(): execution(void setX(int)) || execution(void setY(int)) || execution(void moveBy(int, int)); import before(), after() returning, around() : change(); } Component Color Point setColor setX setY moveBy behavioral composition Connector weave { class Color implements wColor; class Pointimplements wPoint; connect(port1:wColor.change, port2:wPoint.change){ around() : port2 { port2.proceed(); port1.proceed();}} } 14 Example (2) --- Inter-type declaration Weaving-interface public w_interface wColor { pointcut color_property() : field(int color) || method(void setColor(int))|| method(int getColor()); export color_property(); } public w_interface wColorPoint extends wPoint { pointcut thisClass() : class(this); import introduce() : thisClass(); } Component Point Color color setColor getColor setX setY moveBy structural composition Connector weave { class Color implements wColor; class Pointimplements wColorPoint; connect(port1:wColor.color_property, port2:wColorPoint.thisClass) { introduce() : port2 from port1; } } Point color setX setY moveBy setColor getColor 15 Example (3) --- Software evolution with ccJava Component version 1 class Point implements Shape { int x, y; public int getX() { return x; } public int getY() { return y; } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } public void moveBy(int dx, int dy) { x += dx; y += dy; } } Component version 2 class Point implements Shape { int x, y; public int getX() { return x; } public int getY() { return y; } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } public void moveByPlus (int dx, int dy) { x += dx; y += dy; } } Connector weave { class Pointimplements wPoint replacing moveBy with moveByPlus; class Line implements wLine; class Display implements wDisplay; connect(port1:wDisplay.redraw, port2:{wPoint || wLine}.change){ after() returning : port2 { port1.proceed();}} } Weaving-interfaces do not have to be modified ! 16 Example (4) --- Interface for dealing with multiple classes Weaving-interface public w_interface wChange { pointcut change(): execution(void set*(..)) || execution(void moveBy(int, int)); import before(), after() returning, around() : change(); } Connector weave { class Pointimplements wChange; class Line implements wChange; class Display implements wDisplay; connect(port1:wDisplay.redraw, port2:wChange.change){ after() returning : port2 { port1.proceed(); } } } The scope of the weaving impact is limited to classes that implement wChange. We have only to look at Point and Line. 17 4. Implementation 18 Compiler construction ccJava code (weaving-interface) ccJava parser AspectJ code generator Java code (class) ccJava compiler Aspect-Factory class generator AspectJ code (aspect) AspectJ weaver executable program 19 Generated code aspect wPoint { Display display = new DisplayFactory.getInstance(); } generated aspect pointcut change(): execution(void Point.setX(int)) || execution(void Point.setY(int)) || execution(void Point.moveBy(int, int)); after() returning: change() { display.update(); } public class DisplayFactory { private static Display instance = new Display(); public static Display getInstance { return instance; } } generated factory class If a programmer wants to define a specific factory class, … weave { class Display implements wDisplay factory UserDefinedFactory; /* other definitions are omitted */ } 20 5. Related work 21 Related work Aspect-aware interface [Kiczales, et al. 2005] Open modules [Aldrich2005] Crosscutting programming interface (XPI) [Sullivan, et al. 2005] 22 Expressiveness for crosscutting descriptions AspectJ ccJava as an open module ccJava using wildcard NAW NOC NOC/NAW 1 2 1 2 2 2 2 1 2 NWA: number of aspects or weaving-interfaces NOC: number of classes 23 Traceability of weaving impact AspectJ AAIF(*) ccJava NOC IFW NOIF 1 1 1 all aspects number of aspects AAIF 1 weaving-I/Fs number of weaving-IFs * AAIF: Aspect-aware Interface number of all aspects > number of implemented weaving-IFs NOC: number of classes IFW: impact factors for weaving NOIF: number of impact factors 24 6. Conclusion 25 Conclusion A new interface mechanism Weaving-interface A new weaving mechanism based on component-and-connector architecture Flexible Weaving Mechanism ! 26
© Copyright 2024 Paperzz