AspectJ に実装されたリレーションシップ アスペクトを使用すると、次の方法で 2 つのタイプのオブジェクトを関連付けることができます (以下のコード例を参照)。この概念を .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();
}
}