技术开发 频道

J2EE会话外观模式与值对象

     在实际的应用中,我们常常使用值对象模式来代替transfer()方法。值对象在客户端与EJB层之间传递、交换数据。一个值对象实际上是一个包装了业务数据的序列化了的类,下面是此银行系统中代替transfer()方法的值对象:AccountTransferValueObject。
public class AccountTransferValueObject implements java.io.Serializable {      private String customerPK;   private String fromAccountPK;   private String toAccountPK;   private float amount;   ...   public String getCustomerPK(){    return customerPK;   }      public String getFromAccountPK(){    return fromAccountPK;   }      public String getToAccountPK(){    return toAccountPK;   }      public float getTransferAmount(){    return amount;   }      public void setCustomerPK(String customerPK){    this.customerPK = customerPK;   }      public void setFromAccountPK(String fromAccountPK){    this.fromAccountPK = fromAccountPK;   }      public void setToAccountPK(String toAccountPK){    this.toAccountPK = toAccountPK;   }      public void setTransferAmount(float amount){    this.amount = amount;   }   }

    有了值对象,客户端在需要传递数据时候,就把所有的数据打包在值对象中,然后通过网络发送到EJB层,经过Session Facade Bean交给业务逻辑处理。同样当业务逻辑与客户端交互时,EJB层就会创建一个值对象来包装业务方法需要传递的数据,通过Session Façade Bean传递给客户端。

0
相关文章