2 Replies Latest reply on Nov 12, 2002 6:19 AM by Aswin

    -----> SESSION FACADE v/s BUSINESS DELEGATE <-----

    Aswin Newbie

      Hi

      Can anyone help me with my design here - I am not sure whether to use a Session Facade or a Business Delegate in the following scenario:

      [Our application is pure J2EE and does not use EJBs]

      PRESENTATION-TIER
      I have a Command and Control strategy employed in my presentation tier where requests are intercepted by a controller and processed by helpers delegating to appropriate commands and dispatch appropriate responses.

      PRESENTATION-TIER - COMMANDS
      The Commands will invoke appropriate Business Methods in the business tier to retrieve data (mostly).

      BUSINESS-TIER
      Now - most of my business methods use the DAO pattern to retrieve data and are effectively dealing with Data Beans (Value Object beans) - passing them back to commands.

      I can clearly see the use of a generic Interface at the Business tier - i.e., rather than expose the Buiness Methods direcly leading to increased coupling between presentation and business tiers.

      BUT THE CONFUSING PART IS - DO I USE A SESSION FACADE OR A BUSINESS DELEGATE TO INTERFACE WITH MY COMMANDS??? What is the difference? I have looked at Sun's J2EE blueprint and cant make out the clear cut difference between the two.

      Can anyone help?

      thanks
      Aswin

        • 1. Re: -----> SESSION FACADE v/s BUSINESS DELEGATE <-----
          Allen Johnson Newbie

          From what I understand they are quite similar. Usually a BusinessDelegate will wrap a session facade, and if any exceptions are thrown by the session facade (RemoteException or whatever), the businessdelegate will catch them and throw application specific exceptions.

          This will keep the presentation tier completely seperate from the backend tier.

          [Example]

          MySessionFacade has methods:
          public User locateUser(Integer uid) throws RemoteException, NoSuchUserException

          MyBusinessDelegate wraps all the facades methods like this:

          public User locateUser(Integer uid) throws NoSuchUserException, MyLowLevelAppException {
          MySessionFacade sessFacade = null;
          try{
          ... get initialcontext and obtain facadehome ref ...
          sessFacade = home.create();
          return sessFacade.locateUser(uid);
          }catch(NamingException e){
          throw new MyLowLevelAppException(e);
          }catch(CreateException e){
          throw new MyLowLevelAppException(e);
          }catch(RemoteException e){
          throw new MyLowLevelAppException(e);
          }finally{
          try{ if(sessFacade != null) sessFacade.remove(); }
          catch(Exception e){}
          }
          }

          If you plan on implementing the SessionFacade, its usually a good thing to wrap it in a Proxy or BusinessDelegate to keep the two tiers independent.

          Hopes this helps.

          • 2. Re: -----> SESSION FACADE v/s BUSINESS DELEGATE <-----
            Aswin Newbie

            Thanks for your input. That is along the lines of what I had in mind.

            Aswin