在开发Web应用程序的过程中,我们以模块方式提供了所有内容,就像我们的操作类一样,它们负责使用View Business组件和Persistence Component进行操作,并且每个组件都经过了良好的测试和工作细
我的问题是将Action Component与Business Component集成的最佳方法是什么,这样我们就可以实现最大的灵活性以及更高的抽象级别,以便将来对Business层的任何更改都不应强制使用Action中的任何更改成分
另请注意,我们根本没有使用EJB。
答案 0 :(得分:0)
假设你的设计是这样的:
如果希望Action Component与步骤3无关,则使业务组件生成View Component。这是一种javaish方法:
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);
}
}