With relationship aspects implemented in AspectJ I can associate objects of two types in the following way (see code example below). I would like to transfer this concept to .net. Can you point me towards a .net weaver implementation that will allow me to do this or something similar?
Relationship aspects are designed by Pearce & Noble. Read more about the concept and implementation here: http://homepages.ecs.vuw.ac.nz/~djp/RAL/index.html
Im fairly new to AOP and my limited knowledge is obtained from playing around with AspectJ. I have identified that the design benefits from AspectJ's capabilities of supporting intertype declarations and generic types, as well as being able to group weaving rules and advice within the unit of an "aspect".
An example of associating Student and Course objects using a (simplified) relationship aspect:
public class Course02 {
public String title;
public Course02(String title) {this.title = title; }
}
public class Student02 {
public String name;
public Student02(String name) {this.name = name; }
}
public aspect Attends02 extends SimpleStaticRel02<Student02, Course02> {}
public abstract aspect SimpleStaticRel02<FROM,TO>{
public static interface Fwd{}
public static interface Bwd{}
declare parents : FROM implements Fwd;
declare parents : TO implements Bwd;
final private HashSet Fwd.fwd = new HashSet();
final private HashSet Bwd.bwd = new HashSet();
public boolean add(FROM _f, TO _t) {
Fwd f = (Fwd) _f;
Bwd t = (Bwd) _t;
f.fwd.add(_t); // from adder to i fwd hashset
return t.bwd.add(_f); // to adder from i bwd hashset
}
public void printFwdCount(FROM _f)
{
Fwd f = (Fwd) _f;
System.out.println("Count forward is: " + f.fwd.size());
}
public void printBwdCount(TO _t)
{
Bwd b = (Bwd) _t;
System.out.println("Count backward is: " + b.bwd.size());
}
}
public class TestDriver {
public TestDriver() {
Course02 comp205 = new Course02("comp205");
Course02 comp206 = new Course02("comp206");
Student02 Joe = new Student02("Joe");
Student02 Andreas = new Student02("Andreas");
Attends02.aspectOf().add(Joe, comp205);
Attends02.aspectOf().add(Joe, comp206);
Attends02.aspectOf().printFwdCount(Andreas);
Attends02.aspectOf().printFwdCount(Joe);
Attends02.aspectOf().printBwdCount(comp206);
}
public static void main(String[] args) {
new TestDriver();
}
}