hi,
i have a fairly complex domain object with lots of methods. after analyzing it a bit i discovered that i could create multiple extended object types with a (almost) disjunct set of methods that would only be determined by the current state (4 states).
I want to transform this Domain object into the following:
Code:
@Entity
public class Domain() {
private enum State state;
public void method1();
public void method2();
public void method3();
}
transformed:
Code:
@Entity @DiscriminatorColumn("state")
public abstract class Domain() {}
@Entity @DiscriminatorValue("state1")
public State1 extends Domain() {
public void method1() {
state = "state2";
}
}
@Entity @DiscriminatorValue("state2")
public State2 extends Domain() {
public void method2() {}
}
@Entity @DiscriminatorValue("state1")
public State3 extends Domain() {
public void method3() {}
}
So if i change the state of the Domain Object "State1" i could then query for State2.class and have only the appropriate methods available. The user could not invoke the method method1() anymore as it is not relevant anymore. as a benefit the state checks within the current implementation of the methods would disappear (eg. you can't invoke method3() if you are not in state="state3")
is there any way to achieve this? I fact I'm trying to implement a kind of intelligent Memento pattern with Hibernate. My tests with the latest Version 3.5.5 did not succeed.
thanks in advance