27
1 An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture Naoyasu Ubayashi (Kyushu Institute of Technology) Akihiro Sakai (Kyushu Institute of Technology) Tetsuo Tamai (University of Tokyo) November 8, 2007 ASE 2007

An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

  • Upload
    lars

  • View
    24

  • Download
    0

Embed Size (px)

DESCRIPTION

ASE 2007. An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture. Naoyasu Ubayashi(Kyushu Institute of Technology) Akihiro Sakai(Kyushu Institute of Technology) Tetsuo Tamai(University of Tokyo) November 8, 2007. Aspect-oriented Programming. Problem - PowerPoint PPT Presentation

Citation preview

Page 1: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

1

An Aspect-oriented Weaving Mechanism Based on Component and ConnectorArchitecture

Naoyasu Ubayashi (Kyushu Institute of Technology)Akihiro Sakai (Kyushu Institute of Technology)Tetsuo Tamai (University of Tokyo)

November 8, 2007

ASE 2007

Page 2: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

2

Aspect-oriented Programming

AOP is a programming paradigm in which crosscutting concerns are modularized as aspects.

Display updating

after (FigureElement fe): (call(void set*(..)) && target(fe) { fe.display.update(fe); }

advice

pointcut

AspectJ

Problem

A concern considered crosscutting in one situation might be primary in others. It is not desirable to fix a certain concern as either primary or crosscutting.

It is not easy to understand software architecture (the overall behaviorof a woven program).

Page 3: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

3

Today’s my talk

We provide a new weaving mechanism based on component-and-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

Page 4: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

4

Image of our idea

ConcernComponent

(class)

ConcernComponent

(class)

ConcernComponent

(class)

ConcernComponent

(class)

weaving I/F

connector

connector

weaving I/F weaving I/F

weaving I/F Concern weavingby connectors

Contribution

Proposal of

Component-based AOPArchitectural AOP

Towards MDD

Our approach is effective forsoftware modularity, evolution, and reuse.

Page 5: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

5

Outline

1. Motivation2. Weaving-interface & ccJava3. Example programs4. Implementation5. Conclusion & Future work

Page 6: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

6

1. Motivation

Page 7: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

7

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.

client of a class

component (class)programmer

component (class)programmer

interface

interface

Page 8: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

8

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.

Page 9: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

9

Our approach – Weaving-interface

A programmer who defines a weaving has only to be aware of weaving-interfaces.

A programmer of the class can change its implementation without being aware of the client if the class conforms to its weaving-interfaces.

programmerwho connects components

component (class)programmer

component (class)programmer

weaving-interfaceComponentComponent

ComponentComponentConnectorConnector

ConcernComponent

(class)

ConcernComponent

(class)

ConcernComponent

(class)

ConcernComponent

(class)

weaving I/F

connector

connector

weaving I/F weaving I/F

weaving I/F

Component-based AOPArchitectural AOP

Page 10: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

Related work

AAIF: Aspect-aware interface [Kiczales 2005] Open modules [Aldrich 2005] Crosscutting programming interface (XPI)

[Sullivan 2005]An interface is determined only once thecomplete system is known

Point implements FigureElement void setX(int): DisplayUpdating - after returning DisplayUpdating.change();

Aspects can be woven to only exposed program points.Open modules support crosscutting within only one class.

An interface for specifying rules for designing aspects and classes

public aspect XPointChange {/* The purpose of … */ pointcut change(): execution(void Point.setX(int)) || …}

Our Approach

Software Architecture !!

Page 11: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

11

2. Weaving-interface & ccJava

Page 12: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

12

Example --- Figure editor

interface Shape { public void moveBy(int dx, int dy);}

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; }}

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; }}

class Display { public static void update() { /* the detail is ommited */ }}

Three concern components are woven together by component and connector architecture based on weaving-interface.

ComponentComponent

ComponentComponent

ComponentComponent

Page 13: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

13

AO weaving based oncomponent-connector architecture

classDisplay

classPoint

classLine

classLogging

wDisplay wPoint wLine

wLogging

redraw + changeComponentComponent

Weaving-interfaceWeaving-interface

ConnectorConnector

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; }}

change

redraw

class Display { public static void update() { }}

Page 14: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

14

Weaving-interface in ccJavapublic w_interface wPoint { 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();}

public w_interface wDisplay { pointcut redraw(): execution(void update()); import before(), after() returning : redraw(); export redraw();} weave {

class Point implements wPoint; class Line implements wLine; class Display implements wDisplay;

connect(port1:wDisplay.redraw, port2:{wPoint || wLine}.change) { after() returning : port2 { port1.proceed(); }}

ccJava: Class-based Crosscutting language for Java

ConnectorConnector

Port Definition

Port Connection

CoordinationCode

Weaving-interfaceWeaving-interface

Coordination TypeBeforeAfter

Aroundintroduce

Connector descriptions depend on only weaving-interfaces.

Architecture can be represented byWeaving-interface + connector.

Weaving-interface+Connector

is a kind of

ADL(Architecture Description

Language)

Page 15: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

15

3. Example programs

Page 16: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

16

Example (1) --- Method composition

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();}

weave { class Color implements wColor; class Point implements wPoint; connect(port1:wColor.change, port2:wPoint.change){ around() : port2 { port2.proceed(); port1.proceed();}}}

Weaving-interfaceWeaving-interface

ConnectorConnector

Color

setColor

Point

setXsetYmoveBy

behavioralcomposition

ComponentComponent

Page 17: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

17

Example (2) --- Class composition (Inter-type declaration)

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();}

weave { class Color implements wColor; class Pointimplements wColorPoint; connect(port1:wColor.color_property, port2:wColorPoint.thisClass) { introduce() : port2 from port1; }}

Weaving-interfaceWeaving-interface

ConnectorConnector

Color

setColorgetColor

Point

setXsetYmoveBy

structuralcomposition

ComponentComponent

color

Point

setXsetYmoveBysetColorgetColor

color

Page 18: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

18

Example (3) --- Software evolution with ccJava

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; }}

weave { class Point implements 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();}}}

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 1 version 2ComponentComponent ComponentComponent

ConnectorConnector

Weaving-interfaces do not have to be modified !

Renaming

Page 19: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

19

Example (4) --- Interface for dealing with multiple classes

public w_interface wChange { pointcut change(): execution(void set*(..)) || execution(void moveBy(int, int)); import before(), after() returning, around() : change();}

weave { class Point implements 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.

Weaving-interfaceWeaving-interface

ConnectorConnectorclass 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; }}

Page 20: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

20

Evaluation:Expressiveness for crosscutting descriptions

NAW NOC NOC/NAW

AspectJ (AAIF) 1 2 2ccJava as an open module 2 2 1ccJava using wildcard1 2 2

NAW: number of aspects or weaving-interfacesNOC: number of classes (Point, Line)

wPoint wLine

wChange

Good

Weak

Good

DisplayUpdating

Cannot crosscut multiple classes

Can crosscut multiple classes

Page 21: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

21

Evaluation:Traceability of weaving impact

NOC IFW NOIF

AspectJ 1 all aspects number of aspectsAAIF 1 AAIF 1ccJava 1 weaving-I/Fs number of weaving-IFs

NOC: number of classesIFW: impact factors for weavingNOIF: number of impact factors

number of all aspects > number of implemented weaving-IFs

Weak

Good

Good

Linguistic reasoning is

difficultLinguistic

reasoning is easy

Page 22: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

22

4. Implementation

http://posl.minnie.ai.kyutech.ac.jp/

Page 23: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

23

Compiler construction

ccJava code(weaving-interface)

Java code (class)

ccJava parser

AspectJ codegenerator

AspectJ code (aspect)

Aspect-Factoryclass generator

AspectJ weaver

executable program

ccJava compiler

Page 24: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

24

Generated code

aspect wPoint { Display display = new DisplayFactory.getInstance();

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 aspect

generated factoryclass

weave { class Display implements wDisplay factory UserDefinedFactory; /* other definitions are omitted */}

If a programmer wants to define a specific factory class, …

Page 25: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

25

6. Conclusion & Future work

Page 26: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

26

Conclusion

A new interface mechanism Weaving-interface

A new weaving mechanism based on component-and-connector architecture

Flexible Weaving Mechanism !

Page 27: An Aspect-oriented Weaving Mechanism Based on Component and Connector Architecture

Future work

Component-and-connector architecture for integrating OOP and AOP

Integration of weaving-interface and traditional OO interface

27

ConcernComponent

(class)

ConcernComponent

(class)

ConcernComponent

(class)

ConcernComponent

(class)

I/F

connector

connector

I/F I/F

I/F Component-basedConcern-oriented

Progrmming