【问题标题】:A .Net aspect weaver supporting relationship aspect implementation支持关系方面实现的 .Net 方面编织器
【发布时间】:2009-08-20 23:26:14
【问题描述】:

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

【问题讨论】:

    标签: .net aop aspectj


    【解决方案1】:

    我不熟悉关系方面,但你看过PostSharp吗?它是 .NET 方面编织者中的佼佼者。我猜他们支持关系方面。

    【讨论】:

    • 我快速浏览了 PostSharp,但没有彻底浏览。在我投入大量时间之前,我希望得到专家的一些建议。关系方面不是 AspectJ 的一个特性。它是由 Pearce + Noble 设计的一个类库,它利用了 AspectJ 的 AOP 特性,主要是类型间声明。
    猜你喜欢
    • 1970-01-01
    • 2016-12-21
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 1970-01-01
    • 2011-05-16
    相关资源
    最近更新 更多