gpt4 book ai didi

apache-zest - Qi4J 关注部分实现

转载 作者:行者123 更新时间:2023-12-04 02:45:54 26 4
gpt4 key购买 nike

有可能以这样的方式结束:

    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";
}
}

但是使用这种方法只有 Hello 实现被 java 检测到,而不是来自 Service 类的其余内容。那么还有其他可行的方法吗?

最佳答案

我不确定我是否理解您正在尝试做的事情,但是应该更多地将关注视为对它所关注的类的原始实现的包装。正如文档所述:

关注点是一个无状态片段,在调用之间共享,充当对 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." );
}
}

但是,如果您对接口(interface)有顾虑,您还应该实现所述接口(interface):

public abstract class ServiceChild extends ConcernOf<Service> implements Service
{
public String sayHello()
{
return "Rulle Pharfar";
}
}

希望这对您有所帮助。

关于apache-zest - Qi4J 关注部分实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18836221/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com