views:

23

answers:

1

Hi All,

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.

A: 

Assuming your design is something like this:

  1. Http request passed to Action Component.
  2. Action Component accesses Business Component.
  3. something generates View component based on Business Component.
  4. 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);
    }
}


dwb
@Dwb in this case i am again exposing my Business component to Action layer.It might be possible that to accomplish a task i have to call different business services and in that case i have to expose all these business services in my Action layer