支持关系方面实现的 .Net 方面编织器
通过在 AspectJ 中实现关系方面,我可以通过以下方式关联两种类型的对象(请参见下面的代码示例)。 我想把这个概念转移到.net。 您能否向我指出一个 .net weaver 实现,让我能够执行此操作或类似的操作?
关系方面是由 Pearce & 设计的。 高贵。 请在此处阅读有关概念和实现的更多信息: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();
}
}
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对关系方面不熟悉,但是您看过 PostSharp 吗? 它是 .NET 方面编织者中的佼佼者。 我的猜测是他们支持关系方面。
I'm not familiar with relationship aspects, but have you looked at PostSharp? It's the top dog among aspect weavers for .NET. My guess is they support relationship aspects.