Generic Question about Application Design
In the process of development of a web-application we have everything in place in module way like we have our action classes which are responsible for intracting with the View Business component as 开发者_运维知识库well as Persistence Component and every component is well tested and working fine.
My Question is what is the best way to integrate the Action Component with Business Component so that we can achieve maximum flexibility as well as greater level of abstraction so that any future change to Business layer should not force use any change in the Action Component.
Also please note we are not using EJB at all.
Assuming your design is something like this:
- Http request passed to Action Component.
- Action Component accesses Business Component.
- something generates View component based on Business Component.
- Http request passed from Action Component to view (perhaps a JSP).
If want the Action Component to be agnostic to step 3, then make the Business Component generate the View Component. Here is a javaish, approach:
package some.model.package;
class final ViewObject
{
private String something;
public ViewObject(final String something)
{
this.something = something;
}
private String getSomething()
{
return something;
}
}
interface Business
{
Object doBusinessStuff(... HttpServletRequest and other stuff...);
}
package some.model.package;
class final BusinessObject
implements Business
{
... business stuff ...
private String determineSomethingValue()
{
String returnValue;
returnValue = ... determine the value of something ...
return returnValue;
}
private Object getViewObject()
{
ViewObject returnValue;
String somethingValue;
somethingValue = determineSomethingValue();
returnValue = new ViewObject(somethingValue);
return returnValue;
}
Object doBusinessStuff(... HttpServletRequest and other stuff...)
{
... do stuff based on inputs ...
return getViewObject();
}
}
package some.control.package;
class final ActionObject
{
public somehting processHttpRequest(HttpRequest request, ...other parameters...)
{
Business businessObject = ... get the business object from somewhere ...
Object viewObject;
viewObject = businessObject.doBusinessStuff();
request.setAttribute("view object name", viewObject);
}
}
精彩评论