通过在 AspectJ 中实现的关系方面,我可以通过以下方式关联两种类型的对象(参见下面的代码示例)。我想将这个概念转移到.net。你能指点我一个.net weaver 实现,它可以让我这样做或类似的事情吗?
关系方面由 Pearce & Noble 设计。在此处阅读有关概念和实施的更多信息:http: //homepages.ecs.vuw.ac.nz/~djp/RAL/index.html
我对 AOP 相当陌生,我有限的知识是通过玩 AspectJ 获得的。我已经确定该设计受益于 AspectJ 支持类型间声明和泛型类型的能力,以及能够在“方面”单元内对编织规则和建议进行分组。
使用(简化的)关系方面关联 Student 和 Course 对象的示例:
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();
}
}