An Aspect-oriented Weaving Mechanism Based on Component-and-Connector Architecture Naoyasu Ubayashi (Kyushu Institute of Technology) February 12, 2008 Naoyasu Ubayashi, Akihiro Sakai, and Tetsuo Tamai, “An Aspect-oriented Weaving Mechanism Based on Component-and-Connector Architecture”, In ASE’07, pp.154-163 1 POSL Research Group Principles of Software Languages Aspect-oriented programming Reflection Coordination language Modeling language Architecture description language (ADL) Domain-specific language (DSL) Formal methods http://posl.minnie.ai.kyutech.ac.jp/ 2 Recent publications CAiSE 2009 (22nd IEEE/ACM International Conference on Automated Software Engineering) Naoyasu Ubayashi, Akihiro Sakai, and Tetsuo Tamai: An Aspect-oriented Weaving Mechanism Based on Component-and-Connector Architecture. ASE 2005 (20th IEEE/ACM International Conference on Automated Software Engineering) Naoyasu Ubayashi, Genki Moriyama, Hidehiko Masuhara, and Tetsuo Tamai: A Parameterized Interpreter for Modeling Different AOP Mechanisms. ICSE 2005 (1st IEEE International Conference on Software Testing, Verification, and Validation) Naoyasu Ubayashi, Jinji Piao, Suguru Shinotsuka, and Tetsuo Tamai: Contractbased Verification for Aspect-oriented Refactoring. ASE 2007 Naoyasu Ubayashi, Genya Otsubo, Kazuhide Noda, and Jun Yoshida: An Extensible Aspect-oriented Modeling Environment (to appear). ICST 2008 (21st International Conference on Advanced Information Systems) (27th IEEE/ACM International Conference on Software Engineering) Tetsuo Tamai, Naoyasu Ubayashi, and Ryoichi Ichiyama: An Adaptive Object Model with Dynamic Role Binding. 3 My talk ASE’07 + Current work 4 Aspect-oriented Programming AOP is a programming Problem paradigm in which A concern considered crosscutting crosscutting concernsin one situation be primary inas others. It is aremight modularized not desirable to fix a certain concern as either aspects. primary or crosscutting. It is not easy to understand software architecture (the overall behavior of a woven program). Display updating pointcut after (FigureElement fe): (call(void set*(..)) && target(fe) { fe.display.update(fe); } AspectJ advice 5 Our research We provide a new weaving mechanism based on componentand-connector architecture. We propose a new interface mechanism called Weaving-interface. We provide a new AOP language called ccJava. ccJava: Class-based Crosscutting language for Java 6 Image of our idea weaving I/F Concern Component (class) weaving I/F Contribution Concern Component Proposal (class) of weaving I/F Concern Component (class) connector AOP Component-based Architectural AOP connector Towards MDD weaving I/F Concern weaving Our approach is effective for by connectors software modularity, evolution, and reuse. Concern Component (class) 7 Outline 1. 2. 3. 4. 5. Motivation Weaving-interface & ccJava Example programs Implementation Conclusion & Current work 8 1. Motivation 9 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 10 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. 11 Our approach – Weaving-interface A programmer who defines a weaving weaving I/F weaving I/F weaving I/F has only to be aware of weavinginterfaces. Concern Concern Concern Component Component Component A programmer of the class can change (class) (class) (class) its implementation without being aware of the client if the class conforms to its connector weaving-interfaces. connector weaving I/F Connector Concern Component (class) programmer who connects components Component weaving-interface component (class) programmer Component-based AOP Component Architectural AOP component (class) programmer 12 Related work AAIF: Aspect-aware interface [Kiczales 2005] Open modules [Aldrich 2005] An interface is determined only onceinterface the Crosscutting programming (XPI) complete system is known [Sullivan 2005] Aspects can be woven to only exposed program points. Open Point modules implements support FigureElement crosscutting within only one class. void setX(int): DisplayUpdating An interface for specifying rules for designing aspects and classes - after returning OurDisplayUpdating.change(); Approach public aspect XPointChange { Software Architecture !! /* The purpose of … */ pointcut change(): execution(void Point.setX(int)) || … } 2. Weaving-interface & ccJava 14 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 */ } } Three concern components are woven together by component and connector architecture based on weavinginterface. 15 AO weaving based on component-connector architecture Weaving-interface wDisplay redraw class Display Component class Display { public static void update() { } } wLogging class Logging wPoint class Point wLine change class Line redraw + change Connector 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; } 16 } ccJava: Class-based Crosscutting language for Java Weaving-interface in ccJava public w_interface wPoint { Weaving-interface pointcut change(): execution(void setX(int)) || execution(void setY(int)) || Port Definition execution(void moveBy(int, int)); import before(), after() returning, around() : change(); } Weaving-interface+Connector Connector descriptions depend on only weaving-interfaces.Coordination Type is a kind of 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(); } Before Architecture can be represented by After Around Weaving-interface ADL+ connector.introduce (Architecture Description Language) 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; Port Connection class Display implements wDisplay; Coordination Code connect(port1:wDisplay.redraw, } port2:{wPoint || wLine}.change) { after() returning : port2 { port1.proceed(); 17 } 3. Example programs 18 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();}} 19 Example (2) --- Class composition (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(); } Connector weave { class Color implements wColor; class Pointimplements wColorPoint; connect(port1:wColor.color_property, port2:wColorPoint.thisClass) { introduce() : port2 from port1; } } Component Point Color color setColor getColor setX setY moveBy structural composition Point color setX setY moveBy setColor getColor 20 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; } } version 2 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 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();}} } Renaming Weaving-interfaces do not have to be modified ! 21 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(); } class Point implements Shape { int x, y; Connector public int getX() { return x; } weave { public int getY() { return y; } class Pointimplements wChange; class Line implements wChange; public void setX(int x) { this.x = x; } class Display implements wDisplay; public void setY(int y) { this.y = y; } connect(port1:wDisplay.redraw, public void moveBy(int dx, int dy) { port2:wChange.change){ after() returning : port2 { port1.proceed(); x += dx;} }y += dy; } } } The scope of the weaving impact is limited to classes that implement wChange. We have only to look at Point and Line. 22 Evaluation: Expressiveness for crosscutting descriptions NAW AspectJ (AAIF) ccJava as an open module ccJava using wildcard Cannot crosscut multiple classes 1 2 1 NOC NOC/NAW DisplayUpdating wPoint 2 2 2wLine 1 2 2 wChange Good Weak Good Can crosscut multiple classes NAW: number of aspects or weaving-interfaces NOC: number of classes (Point, Line) 23 Evaluation: Traceability of weaving impact Linguistic reasoning Linguisticis NOC IFW difficult reasoning is AspectJ AAIF ccJava 1 NOIF easy 1 all aspects number of aspects Weak 1 AAIF 1 Good weaving-I/Fs number of weaving-IFs Good number of all aspects > number of implemented weaving-IFs NOC: number of classes IFW: impact factors for weaving NOIF: number of impact factors 24 4. Implementation 25 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 26 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 */ } 27 Verifiable AO MDD Architectural Design Designs and verifies an architecture represented by a set of weaving-interfaces (Alloy-based architecture verification) Not Weaving-interface Java only programming-level but also design-level notion ADL for bridging a gap Implements verified between architectural weaving interfaces design and implementation 28 ccModeler & ccJava Architectural Design ccModeler Architecture Design & verification Designs and verifies an architecture represented by a set of weavinginterfaces Weaving-interface Java ccJava Refinement Implements verified weaving interfaces 29 6. Conclusion & Current ongoing work 30 Conclusion A new interface mechanism Weaving-interface A new weaving mechanism based on component-and-connector architecture Flexible Weaving Mechanism ! 31 Current work -- From Weaving-interface to Archface Archface: architectural interface for bridging a gap between design modeling and implementation Archface integrates not only design modeling with its implementation but also AO with OO. 32 Example: Observer Pattern Archface In archface, a collaborative architecture is specified by a set of ports based on the pointcut mechanism. Implementation Pointcut-based interface 33