I have been reading the CMP 2.0 specification and I think it is simply
great! Still, I am a bit surprised that the bean developer has no control
over what happens when a field is set. Imagine an AccountBean, for instance:
public abstract class AccountBean extends EntityBean {
//implemented by the persistence manager
public abstract Float getBalance();
//implemented by the persistence manager
public abstract void setBalance(Float balance);
}
What if I wanted to do something useful when the balance was set? Say, I
wanted to add the account to a list of surveilled accounts if a negative
balance was set... it seems I cannot do that because the container
implements the setBalance() method for me. And I cannot just declare a
setBalance() method myself because I need the container's implementation or
I will not be able to store the balance. Hmmmm... it seems this is going to
leave me with something like
public abstract class AccountBean extends EntityBean {
public abstract Float getBalance();
public abstract void setBalance(Float balance);
public void setBalanceAndDoWhatHasToBeDoneWhenYouSetBalance(Float balance)
{
//check if balance is negative and take action
...
setBalance(balance);
}
}
Now I have _no_ guarantee that nobody will accidently call the original
setBalance() method, thereby circumventing my little security system, which
was supposed to check for a negative balance. But, hey, I thought, then I
will just declare the original setBalance() as protected - unfortunately
that is not allowed by the specification.
I would r e a l l y like to hear from anybody who knows a solution to this.
Any comments would be most welcomed.
Randahl