1

I'm having a problem with active objects library (https://java.net/projects/activeobjects/pages/Home).

Let's say i have ao entity like this:

@Implementation(PersonImpl.class)
interface Person extends Entity{

    public String getName();

    public String setName();
}

And the implementation class of this entity :

class PersonImpl {

    private Person person;

    public PersonImpl(Person person){
        this.person = person;
    }

    public String getName(){
       if( isTodayIsMonday() )
           return "I hate monday";
       else
           return person.getName();
    }
}

Problem is in PersonImpl class. Because of person.getName() I get infinite recursion (impl class is always invoked). How can I skip invoking implementation (in PersonImpl class) and just get name from database?

4

2 回答 2

1

根据http://www.javalobby.org/articles/activeobjects/,ActiveObjects 通过检查调用堆栈自动避免了这个问题:

“我们可以使用它来检查堆栈上一步定义的实现。如果我们发现它启动了方法调用,我们将跳过重新调用定义的实现并实际正常执行方法调用。因此,从定义的实现对实体的任何调用都将跳过任何实现逻辑,从而避免递归。”

于 2013-09-19T09:32:23.663 回答
0
private String getMyName(boolean isMonday) {
  if (isMonday) {
    return "I hate Monday";
  }
  return person.getName();
}
于 2013-09-19T08:29:28.413 回答