aspectual components part 2 april 5, 1999. composition example use three aspects simultaneously with...

69
Aspectual Components Part 2 April 5, 1999

Upload: sheena-lindsey

Post on 21-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Aspectual ComponentsPart 2

April 5, 1999

Page 2: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Composition example

• Use three aspects simultaneously with three classes.

• Three aspects:– ShowReadWriteAccess– InstanceLogging– AutoReset

• Three classes: Point, Line, Rectangle

Page 3: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Shapes (Point, Line, Rectangle)AutoReset

ShowReadWriteAccess

InstanceLogging

Point

Line

Rectangle

Weaved Code

Page 4: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Inheritance between components

component ShowReadWriteAccess extends ShowReadAccess {

participant DataToAccess {

expect void writeOp(Object[] args);

replace void writeOp(Object[] args){

System.out.println(

"Write access on " +

this.toString());

expected(args);}}

}

Page 5: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

InstanceLogging component(first part)

component InstanceLogging {

participant DataToLog {

expect public DataToLog(Object[] args);

replace public DataToLog(Object[] args) {

expected(args);

long time = System.currentTimeMillis();

try {

String class = this.class.getName() + " ";

logObject.writeBytes(""New instance of " + class +

at "" " + time + "" " \n");

} catch (IOException e)

{System.out.println(e.toString());}

}

}

Page 6: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

InstanceLogging component(second part)

protected DataOutputStream logObject = null;

public init() {

try {logObject = new DataOutputStream(

new FileOutputStream(log));}

catch (IOException e)

{System.out.println(e.toString());}

}

}

Page 7: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

AutoReset component

component AutoReset {

participant DataToReset {

expect void setOp(Object[] args);

expect void reset();

protected int count = 0;

replace void setOp(Object[] args) {

if ( ++count >= 100 ) {

expected(args);

count = 0;

reset();

}}

}

}

Page 8: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Composition of components

connector CompositionConn1 {

{Line, Point} is ShowReadWriteAccess.DataToAccess with

{ readOp = get*; writeOp = set*;};

Point is AutoReset.DataToReset with {

setOp = set*;

void reset() { x = 0; y = 0; }

};

{Line, Point, Rectangle} is

InstanceLogging.DataToLog;}

Page 9: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

ShapesAutoReset

ShowReadWriteAccesses

InstanceLogging

Point

Line

Rectangle

Weaved Code

Page 10: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Composition of components

Connector graph CompositionConn1 Line, Point, Rectangle

ShowReadWriteAccess.DataToAccess * *

AutoReset.DataToReset *

InstanceLogging.DataToLog * * *

Page 11: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Modified composition

connector CompositionConn2 extends CompositionConn1 {

Line is AutoReset.DataToReset with {

setOp = set*;

void reset() {init();}

};

}

Page 12: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Composition of components

Connector graph CompositionConn1 Line, Point, Rectangle

ShowReadWriteAccess.DataToAccess * *

AutoReset.DataToReset *

InstanceLogging.DataToLog * * *

Connector graph CompositionConn2 Line, Point, Rectangle

ShowReadWriteAccess.DataToAccess * *

AutoReset.DataToReset * *

InstanceLogging.DataToLog * * *

Page 13: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Modify existing connection statements

connector CompositionConn3 extends CompositionConn1 {

Point is AutoReset.DataToReset with {

{ setOp = set;

void reset() {

x = 0; y = 0; }}

{ setOp = setX;

void reset() { x = 0;}}

{

setOp = setY;

void reset() { y = 0;}}

};

}

Page 14: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Composition of components

Connector graph CompositionConn3 Line, Point, Rectangle

ShowReadWriteAccess.DataToAccess * *

AutoReset.DataToReset ***

InstanceLogging.DataToLog * * *

overridden: ***

Page 15: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

New example: Feature-oriented Programming

• Dependent aspects

• Order of deployment is relevant

Page 16: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

DataWithCounter componentpairwise interaction Data/Countercomponent DataWithCounter {

private participant Counter { int i=0;

void reset(){i=0;}; void inc(){…}; void dec(){…};}

participant DataStructure {

protected Counter counter;

expect void initCounter();

expect void make_empty();

expect void push(Object a);

expect void pop();

replace void make_empty(){counter.reset();expected();}

replace void push(Object a){counter.inc(); expected(a);}

replace void pop() {counter.dec();expected();}

}

}

Page 17: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

DataWithLock Componentpairwise interaction Data/Lock

component DataWithLock {

participant Data {

Lock lock;

expect void initLock();

expect AnyType method_to_wrap(Object[] args);

replace AnyType method_to_wrap(Object[] args) {

if (lock.is_unlocked()) {

lock.lock();

expected(Object[] args);

lock.unlock(); }}}

private participant Lock {boolean l = true;

void lock(){…};

void unlock(){…};

boolean is_unlocked(){return l};}

Page 18: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

StackImpl

QueueImpl

DataWithCounter

DataWithLock

Counter

Lock

Page 19: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

First connectorconnector addCounter&Lock {

StackImpl is DataWithCounter.DataStructure

with {

void initCounter() {counter = new Counter();}

void push(Object obj) {push(obj));} // use name map instead

Object top() {return top();}

...

} is DataWithLock.Data

with {

method_to_wrap = {pop, push, top, make_empty, initCounter};

};

QueueImpl is DataWithCounter.DataStructure with {

... } is DataWithLock.Data with { ... };

}

Page 20: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

DataWithCounter

DataWithLock DataWithCounter&Lock

Page 21: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Create composed aspects prior to deployment

component DataWithCounterAndLock {

participant Data =

DataWithCounter.DataStructure is

DataWithLock.Data with {

method-to-wrap =

{make_empty, pop, top, push}};

}

Page 22: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Second connector: Deploy composed component

connector addCounter&Lock {

StackImpl is DataWithCounterAndLock.Data with {

void make_empty() {empty();}

void initCounter() {

counter = new Counter();}

void push(Object obj) {push(obj);}

...

};

QueueImpl is DataWithCounterAndLock.Data with {...};

}

Page 23: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Defining New Behavior: The Publisher-

Subscriber Aspect

an aspect can be multiply deployed with the same application, each deployment with its own mappings.

Page 24: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Publisher

component PublisherSubscriberProtocol {

participant Publisher {

expect void changeOp(Object[] args);

protected Vector subscribers = new Vector();

public void attach(Subscriber subsc) {

subscribers.addElement(subsc);}

public void detach(Subscriber subsc) {

subscribers.removeElement(subsc);}

replace void changeOp() {

expected();

for (int i = 0; i < subscribers.size(); i++)

{((Subscriber)subscribers.elementAt(i)).

newUpdate(this);}}

Page 25: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Subscriber

participant Subscriber {

expect void subUpdate(Publisher publ);

protected Publisher publ;

public void newUpdate(Publisher aPubl) {

publ = aPubl;

subUpdate(publ);}

}

}

}

Page 26: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Class for deployment

class ChangePrinter {

void public printR() {

System.out.println("Printer: " + this.toString() +

" read access has occurred ..." + \n);

}

void public printW() {

System.out.println("Printer: " + this.toString() +

" write access has occurred ..." + \n);

}

void public notifyChange() { System.out.println("CHANGE ...");

}

}

Page 27: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Deployment 1

connector PubSubConn1 {

Point is Publisher with

{ changeOp = {set*, get*};}

ChangePrinter is Subscriber with {

void subUpdate(Publisher publ) {

notifyChange();

System.out.println(”on Point object " +

((Point) publ).toString());

}

}

}

Page 28: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Deployment 2

connector PubSubConn2 {

TicTacToe is Publisher with {

changeOp = {startGame, newPlayer, putMark,

endGame}};

{BoardDisplay, StatusDisplay} is Subscriber with {

void subUpdate(Publisher publ) {

setGame((Game) publ);

repaint();

}

};

}

Page 29: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Deployment/write

connector PubSubConn3 {

Point is Publisher with { changeOp = set*;}

ChangePrinter is Subscriber with {

void subUpdate(Publisher publ) {

printW();

System.out.println("on point object " +

((Point) publ).toString());

}

}

}

Page 30: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Deployment/read

connector PubSubConn4 {

Point is Publisher with { changeOp = get*;}

ChangePrinter is Subscriber with {

void subUpdate(Publisher publ) {

printR();

System.out.println("on point object " +

((Point) publ).toString());

}

}

}

Page 31: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Overlap between connectors

The sets of operations of Point that are mapped to different notification operations of the subscriber participant need not be disjoint. For instance, we may want to distinguish between set operations that affect the x-coordinate, respectively, the y-coordinate of a point.

The set(int, int), however, will then fall in both categories. This is expressed by the connectors PubSubConn3_1 and PubSubConn3_2 below.

Page 32: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Deployment/write

connector PubSubConn3_1 {

Point is Publisher with { changeOp = {set,setX};}

ChangePrinter is Subscriber with {

void subUpdate(Publisher publ) {

printW();

System.out.println("on point object " +

((Point) publ).toString());

}

}

}

Page 33: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Deployment/write

connector PubSubConn3_2 {

Point is Publisher with { changeOp = {set, setY};}

ChangePrinter is Subscriber with {

void subUpdate(Publisher publ) {

printW();

System.out.println("on point object " +

((Point) publ).toString());

}

}

}

Page 34: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Mapping Participant Graphs

• Is the deployment of a component giving the intended result?

• Example: Three participants: A, B, C– A has 0..* B; B has 1..* C.

– A::f(int x1){for each b: f(x1);}

– B::f(int x1){for each c: f(x);} // x a data member local to B

– C::f(int x1){print(“at C: number at previous B”); print(x1);}

Page 35: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Expected output

at C: number at previous B 78

at C: number at previous B 8

Page 36: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

MappingA CB

A BC

1..*0..*

Page 37: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Refinement

This property must hold between a PG and a corresponding CG or another PG. The intent of the refinement relation is to ensure that the behavior in the component will be properly instantiated at the place of use without ``surprising'' behavior.

Page 38: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

A A

B BC C

D DE E

F F

G1

G2

G1 refinement G2

refinement: connectivity of G2is in pure form in G1Allows extra connectivity.

Page 39: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

A A

B BC C

D DE E

F F

G1

G2

G1 refinement G2

refinement: connectivity of G2is in pure form in G1

Page 40: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

A A

B BC C

D DE E

F F

G1

G2

G1 compatible G2

Compatible: connectivity of G2 is in G1

Page 41: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

A A

B BC C

D DE E

F F

G1

G2

G1 strong refinement G2

refinement: connectivity of G2is in pure form in G1 and G1 contains nonew connections in terms ofnodes of G2

Page 42: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Key concepts: refinement

• Let G1=(V1,E1) and G2=(V2,E2) be directed graphs with V2 a subset of V1. Graph G1 is a refinement of G2 if for all u,v in V2 we have that (u,v) in E2 implies that there exists a path in G1 between u and v which does not use in its interior a node in V2.

• Polynomial time.

Page 43: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Refinement

• For each edge in G2 there must be a corresponding pure path in G1.

• Pure path = in interior no nodes of G2.

• Refinement = strong refinement with “if and only if” replaced by “implies”.

Page 44: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

A A

B BC C

D DE E

F F

G1

G2

G1 refinement G2

Implementation: create strategyconstraint map: bypassing allnodes

Page 45: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

A A

BB

G1

G2

not G1 refinement G2

C C

Refinement means: no surprises

Page 46: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

A A

BB

G1

G2

G1 refinement G2

C C

Refinement means: no surprises

X

Page 47: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

A

B

G2G1

not G1 refinement G2

C

Refinement means: no surprises

A

B C

Page 48: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Alternative definition

a graph G is a refinement of a graph S, if S is a connected subgraph of the pure transitive closure of G with respect to the node set of S.

Page 49: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Pure transitive closure

• The pure transitive closure of G=(V,E) with respect to a subset W of V is the graph G*=(V,E*), where E*={(i,j): there is a W-pure path from vertex i to vertex j in G}.

• A W-pure path from i to j is a path where i and j are in W and none of the inner nodes of the path are in W.

Page 50: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Implementation issues

• Translate to AspectJ: requires source code access.

• What if aspectual components only in binary?

• Want separate compilation of application and aspectual components.

Page 51: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Interfaces between components and application

• Usage interface– expected in order to be used by participants

• Modification interface– expected in order to be replaced by the aspect

Page 52: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Writing components directly in Java

• Benefit: no new language to learn

Page 53: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Participants as abstract classes

class AutoReset {

abstract class DataToReset {

abstract void reset();

protected int count = 0;

void replaced_setOp(Object thisObject, Class thisClass,

Method expected_setOp, Object[] args) {

if ( ++count >= 100 ) {

expected_setOp.invoke(thisObject, args);

count = 0;

reset();

}

}

}

}

Page 54: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

AutoReset component

component AutoReset {

participant DataToReset {

expect void setOp(Object[] args);

expect void reset();

protected int count = 0;

replace void setOp(Object[] args) {

if ( ++count >= 100 ) {

expected(args);

count = 0;

reset();

}}

}

}

Page 55: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

What about connectors in Java?

• Translation to Java not straight-forward

Page 56: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Approach

• Methods in– usage interface: abstract methods– modification interface: x() translated to replaced_x(). Expected implementation of x() will be a parameter to replaced_x().

x=setOpvoid replaced_setOp(Object thisObject, Class thisClass,

Method expected_setOp, Object[] args) {

if ( ++count >= 100 ) {

expected_setOp.invoke(thisObject, args);

Page 57: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Approach

Question: Why is thisClass used as an argument? Is not used in this example.

void replaced_setOp(Object thisObject, Class thisClass,

Method expected_setOp, Object[] args) {

if ( ++count >= 100 ) {

expected_setOp.invoke(thisObject, args);

Page 58: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Binary Adaptation of Application Classes

• Application classes are turned into event publishers by adding a field that stores a set of subscribers (from connectors).

• Any application operation op that is mapped to expected operation in modification interface: renamed to expected_op

• new implementation of op: invokes notify on subscribers

Page 59: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Pseudo-code simulating binary adaptation

class Point {

public static java.util.Vector aspectSubscribers;

// added variable

public void addSubscriber(AspectSubscriber sub) {

// added operation

aspectSubscribers.addElement((Object) sub);}

private int x = 0;

private int y = 0;

Page 60: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Pseudo-code simulating binary adaptation

void expected_set(int x, int y) { // renamed

this.x = x; this.y = y;}

void set(int x, int y) { // reimplemented

Object[] args =

{(Object) new Integer(x), (Object) new Integer(y)};

Class[] argTypes = {Integer.TYPE, Integer.TYPE};

Method expected_set =

thisClass.getMethod("expected_set", argTypes);

Enumeration subscribers = aspectSubscribers.elements();

while (subscribers.hasElements()) {

Object sub = subscribers.next();

sub.notify(this, this.getClass(), expected_set, args);}}

…}

Page 61: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Generating Connector Classes

• Generate a class for each connector

• Example: CompositionConn3

Page 62: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Recall: CompositionConn1

connector CompositionConn1 {

{Line, Point} is ShowReadWriteAccess.DataToAccess with

{ readOp = get*; writeOp = set*;};

Point is AutoReset.DataToReset with {

setOp = set*;

void reset() { x = 0; y = 0; }

};

{Line, Point, Rectangle} is

InstanceLogging.DataToLog;}

Page 63: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Recall: CompositionConn3

connector CompositionConn3 extends CompositionConn1 {

Point is AutoReset.DataToReset with {

{ setOp = set;

void reset() {

x = 0; y = 0; }}

{ setOp = setX;

void reset() { x = 0;}}

{

setOp = setY;

void reset() { y = 0;}}

};

}

Page 64: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Connector Class code

interface AspectSubscriber {

void notify(Object thisObject,

Class thisClass, Method expected_meth,

Object[] args);}

interface Evaluable {

void eval(Object thisObject,

Class thisClass, Method expected_meth,

Object[] args);}

Page 65: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

Connector class generated

class CompositionConn3 implements AspectSubscriber {

public static singleInstance = new CompositionConn3();

java.util.Hashtable mappings = new java.util.Hashtable();

abstract class Point_DataToReset_setOp extends

AutoReset.DataToReset implements Evaluable {

private Point host;

public void eval(Object thisObject, Class thisClass,

Method expected_meth, Object[] args) {

host = (Point) thisObject;

replaced_setOp(thisObject, thisClass, expected_meth, args);

}

}

Page 66: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

public CompositionConn3() {

Object[] argTypes = {Integer.TYPE, Integer.TYPE};

Method expected_set = Point.getMethod("expected_set", argTypes);

argTypes = {Integer.TYPE};

Method expected_setX = Point.getMethod("expected_setX", argTypes);

Method expected_setY = Point.getMethod("expected_setY", argTypes);

mappings.put((Object) expected_set,

(Object) new Point_DataToReset_setOp() {

void reset() {host.expected_set(0, 0);}});

mappings.put((Object) expected_setX,

(Object) new Point_DataToReset_setOp() {

void reset() {host.expected_setX(0);}});

mappings.put((Object) expected_setY, (Object)

(Object) new Point_DataToReset_setOp() {

void reset() {host.expected_setY(0);}});

Point.addSubscriber(this);}

Page 67: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

ComponentPackage

Component

Participant expectedOp() Op(){expectedOp(); getHost()} getHost()

ConnectorPackage

HostPackage

Host // to play role of participant toModify(){} // to be mapped to Op()

Johan’s solution 1 based on Mira’s inner class solution.Modification interfaceis represented also byabstract class, not byMethod argument asproposed by Mira.

“outer.super.toModify()” simulatedwith aux() is not elegant

MyHost toModify(){part.Op();}// override aux(){super.toModify()} part

ParticipantAnonymousExtended expectedOp(){aux()} getHost(){MyHost.this} main(){new MyHost().toModify() }

Page 68: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

ComponentPackage

Component

Participant expectedOp() Op(){expectedOp(); getHost()} getHost()

ConnectorPackage

MyHost toModify(){part.Op();} aux(){super.toModify()} part

HostPackage

ParticipantAnonymousExtended expectedOp(){aux()} getHost(){MyHost.this} main(){new MyHost().toModify() }

Host toModify(){}

Does it work with multipleparticipants? With multiple hosts?Looks like.

Problem: when we have a Host-object and want to getmodified behavior, need to create a MyHost object.

Page 69: Aspectual Components Part 2 April 5, 1999. Composition example Use three aspects simultaneously with three classes. Three aspects: –ShowReadWriteAccess

ComponentPackage

Component

Participant expectedOp() Op(){expectedOp(); getHost()} getHost()

ConnectorPackage

More complex connector:one host but multiple methodsare modified. Createsmultiple inheritance!?Is this why Mira’s implementationis more complex?

part2ParticipantAnonymousExtended expectedOp(){aux2()} getHost(){MyHost.this} main(){new MyHost().toModify2()}

toModify2(){part2.Op();}//overrideaux2(){super.toModify2()}

ParticipantAnonymousExtended expectedOp(){aux1()} getHost(){MyHost.this} main(){new MyHost().toModify1()}

MyHost toModify1(){part1.Op();}//overrride aux1(){super.toModify1()} part1