Tuesday, June 02, 2009

Design patterns - Session Facade

Design patterns - Session Facade (source)

Business processes involve complex manipulation of business processes. Business classes participate in several business processes. If the responsibility of orchestrating (making the calls on business objects [may be session and entity beans] necessary to achieve a business process) the business process is placed with the clients of business objects, then clients become difficult to write and business objects themselves become tightly coupled. 

The session facade defines a higher level component that abstracts the complex interactions between lower level business components. Session facade in implemented in a session enterprise bean. It provides a single interface for clients to achieve a full business process or a part of it. It also decouples lower lever business components from one another.

Facade in french means face. Hence the facade component exposes a single face for a business process.

Giving access to each small interface on the lower level business components increases network traffic and latency. 


Example: Approval of large purchase orders may be a complex business process involving several business objects. In this case a OPCAdminFacade (Order Processing Center) facade ay be introduced that exposes APIs to achieve order processing. In this case the UI code will interface with only the OPCAdminFacade and not with each of the business objects.

public interface OPCAdminFacade extends EJBObject {

public OrdersTO getOrdersByStatus(String status)
throws RemoteException, OPCAdminFacadeException;

public Map getChartInfo(String request,
Date start,
Date end,
String requestedCategory)
throws RemoteException, OPCAdminFacadeException;
}

OPCAdminFacade would be implemented in OPCAdminFacadeEJB.


The getOrdersByStatus would interface with ProcessManagerLocal and ManagerLocal to get a list of PurchaseOrderLocal entity beans. It then creates a List of transfer objects (OrderDetailsTO [transfer object]) and returns them to the client.

No comments: