|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 4
The two main benefits to loading business objects dynamically with this scheme are that you can avoid a registration step and can add functionality to the application on the fly. Both of these advantages stem from the fact that there is no need to specifically hardcode the possible actions contained in the servlet.
In Part 2 of this series, I'll expand on the benefits of the Reflection API and show some more benefits to this framework. Reflection will make it possible to further reduce the amount of code while greatly increasing the functionality contained within.
Factory class discussed above. In this example, the servlet is used as the controller, data interface, and presentation interface.
The example uses extremely simple business objects that show the dynamic behavior contained in the servlet, but not the complete
functionality of the system, as that is beyond the scope of the article.The Proxyservlet service method is the heart of the framework:
public void service(HttpservletRequest req, HttpservletResponse res)
throws servletException, IOException
{
// convert the request into a hashtable
Hashtable requestHT = getHashtableFromRequest(req);
// retrieve the actionName from the hashtable
actionName = getCurrentAction(requestHT);
// Create a business Object
BusinessInterface bi = getBusinessObject(actionName);
try
{
// Initialize the business object
bi.init( (ProxyInterface) this, requestHT);
} catch (Exception e)
{
// Any exception handling code goes here
}
}
In the code above, the servlet converts the HttpservletRequest into a simple hashtable containing the name-value pairs. It then retrieves the actionName from the hashtable and creates the BusinessInterface implementation. The last step is to initialize the BusinessInterface and let it perform any necessary processing.
This simple example ignores some of the session handling that can be in the service method. This processing can either be handled by the servlet, or in the business object through methods in the proxy interface.
It is up to the developer to make the design decision as necessary.
init method of the BusinessInterface object. This try-catch actually ensures that all error handling can be performed in the same location within the controller.
This allows the developers to handle minor exceptions within their business objects and to pass major exceptions up to a single
point in the code to ensure that all errors are handled together.In the second of part this series, I'll expand on some other error-handling additions we can make to this framework to increase its power and expandability.
Using this framework allows developers to efficiently design an object-oriented, server-side solution without tying it into the platform upon which it was developed. This provides key benefits if you want to add new features to the system, or if you later decide to port it to another server product.