Discussions

J2EE patterns: Super Remote Interface Extended to Session Facade

  1. We had a situation where we used Session Facade pattern to handle a number of business operations. We had a number of such Session Beans which almost exhibited similar behavior. Following are few example interfaces
    CacheEntity getEntity(String pk);
    updateEntity(CacheEntity entity);
    Vector getAllEntities();
    createEntity(CacheEntity entity);
    deleteEntity(CacheEntity entity);

    There where 15 similar session beans what we did was to put all these methods into one Super Interface and all the session facades just extended this interface. In the Application we did not care much about which Session Bean are we operating on as long as it supported the Super Interface.

    Lookup of the Session Beans was also made simple, we had an SessionBeanStore EJB which keeps trace of all the Session Bean and supported an very generic interface getSessionBean(SessionBeanName) which returned an Remote Reference of Session Facade.

    So at the end of the day what we need is four line of code to call an update method.

    SessionBean company = SessionBeanStore.getSessionBean(“Company”);
    CacheEntity company = company.getEntity(companyName);
    company.setCEO(“Sachin Gupta”);
    company.updateEntity(company);

    Also the Implementation of each Session Bean was much simple and straight forward.

  2. This is pretty close to the Data Access Object (DAO) pattern but applied to the business / service layer.

    http://www.javaworld.com/javaworld/jw-03-2002/jw-0301-dao.html

    P.