Apache zest Qi4J涉及部分实现
有可能最终得到这样的结果:Apache zest Qi4J涉及部分实现,apache-zest,Apache Zest,有可能最终得到这样的结果: ServiceChild (class) extends (or only partial implements) Service and overrides sayHello Service (interface) implements hello,goodbye Hello (has a mixin HelloMixin) has method sayHello Goodbye (has a mixin GoodbyeMixin)
ServiceChild (class) extends (or only partial implements) Service and overrides sayHello
Service (interface) implements hello,goodbye
Hello (has a mixin HelloMixin) has method sayHello
Goodbye (has a mixin GoodbyeMixin) has method sayGoodbye
我已经尝试在ServiceChild中使用关注方法来完成上述工作
public class ServiceChild extends ConcernOf<Service> implements Hello
{
@Override
public String sayHello() {
return "Rulle Pharfar";
}
}
公共类ServiceChild扩展了ConcernOf实现Hello
{
@凌驾
公共字符串sayHello(){
返回“Rulle Pharfar”;
}
}
然而,使用这种方法,java只检测Hello实现,而不检测服务类中的其他内容。那么还有其他方法可以工作吗?我不确定我是否理解您正在尝试做什么,但是一个关注点应该更多地被视为它所关注的类的原始实现的包装。 如文件所述: 关注点是一个无状态片段,在调用之间共享,充当Mixin调用的拦截器 通常会这样做:
//Given interface MyStuff
@Mixins( MyStuff.Mixin.class )
@Concerns( MyStuffConcern.class )
public interface MyStuff
{
public void doStuff();
abstract class Mixin implements MyStuff
{
public void doStuff()
{
System.out.println( "Doing original stuff." );
}
}
}
public class MyStuffConcern extends ConcernOf<MyStuff>
implements MyStuff
{
public void doStuff()
{
// if I want to do anything before going down the call chain I'll do it here
System.out.println( "Doing stuff before original." );
// calling the next concern or actual implementation
next.doStuff();
// anything to do after calling down the call chain - here is the place for it
System.out.println( "Doing stuff after original." );
}
}
//给定接口MyStuff
@Mixin(MyStuff.Mixin.class)
@关注点(MyStuffConcern.class)
公共接口MyStuff
{
公共无效doStuff();
抽象类Mixin实现了MyStuff
{
公共空间
{
System.out.println(“做原创的东西”);
}
}
}
公共类MyStuffConcern扩展了关注点
我的凝灰岩
{
公共空间
{
//如果我想在进入呼叫链之前做点什么,我会在这里做
System.out.println(“在原创之前做东西”);
//调用下一个关注点或实际实现
接下来是doStuff();
//调用呼叫链后要做的任何事情-这里是它的位置
System.out.println(“在原创之后做东西”);
}
}
但是,如果您对接口有顾虑,您也应该实现所述接口:
public abstract class ServiceChild extends ConcernOf<Service> implements Service
{
public String sayHello()
{
return "Rulle Pharfar";
}
}
公共抽象类ServiceChild扩展ConcernOf实现服务
{
公共字符串sayHello()
{
返回“Rulle Pharfar”;
}
}
希望这有帮助。我也不完全理解这个问题 正如Arvice所说,关注点相当于AOP中的around建议,具有更精确的切入点语义。尽管关注点“包装”底层关注点/混合点在技术上是正确的,但我更愿意将其视为“拦截器”,而不是“包装器”。处理的是来电。概念上稍有不同,可能不适用于所有人 也有可能,关注点(无状态)和mixin(有状态)仅通过使类“抽象”来实现它们覆盖的接口中方法的一个子集。Qi4j将填充缺少的(和未使用的)方法调用。并且可以使用任何组合 此外,实现良好的关注点应该称为“下一个”,因为它们应该不知道它们的实际用途。如果期望关注点处理方法调用。每个复合类型方法都必须有一个Mixin,否则程序集将失败 简言之; 1.Mixin实现可以实现零(也称为私有Mixin),即复合类型接口的一个或多个方法。 2.关注点可以实现复合类型接口的一个或多个方法 还值得注意的是,当类(mixin或concern)调用复合类型接口中它自己的方法时,调用将不是类内的,而是从外部调用复合,因此调用整个调用堆栈,以确保内部调用和外部调用的结果相同。如果需要绕过,则存在模式