Java Validation With Dynamic Proxies
By Eric Olson2005-05-14
The business object implementation
The next step is to specify a business object implementation to the constructor of the invocation handler. For the purpose of this example I'll use a validation-free implementation of the User interface, because the validation logic is being handled in the invocation handler. The relevant code from the implementation class is shown in Listing 5.
Listing 5. The validation-free User implementation
/**If you compare the setPassword() method body above to that in Listing 2, you will see that it contains no code specific to validation. The details of the validation process are now handled entirely by the invocation handler.
* The username of this User.
*/
private String username = null;
/**
* The password of this User.
*/
private String password = null;
/**
* Gets the username of the User.
*/
public String getUsername() {
return username;
}
/**
* Sets the username of the User.
*/
public void setUsername(String username) {
this.username = username;
}
/**
* Gets the password of the User.
*/
public String getPassword() {
return password;
}
/**
* Sets the password of the User.
*/
public void setPassword(String password) {
this.password = password;
}
Tutorial Pages:
» Decouple validation processes from your business object implementations
» Tightly coupled validation
» Loosely coupled validation
» The dynamic proxy approach
» The invocation handler
» The business object implementation
» The business object factory
» Drawbacks of dynamic proxies
» Other uses for dynamic proxies
» Conclusion
» Resources
First published by
