Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Your Email:

Java Validation With Dynamic Proxies

By Eric Olson
2005-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

/**

* 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;
}
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.

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

Related Tutorials:
» All about JAXP, Part 1
» Make Database Queries Without the Database
» Load List Values for Improved Efficiency
» 2 Ways To Implement Session Tracking
» A Simple Way to Read an XML File in Java
» Develop Aspect-Oriented Java Applications with Eclipse and AJDT