在设计模式2中我们看到,在entity bean和struct之间有很多重复的代码比如同样的字段声明(对应 数据库中的表列)。如果让entity bean从结构继承下来就可以避免冗余的代码。但是这种设计,仍然不能显示beans之间的联系。 Code snippet for Company Entity Bean public class CompanyBean extends CompanyStruct { implements EntityBean EntityContext entityContext; //all fields in CompanyStruct are available for CMP public Integer ejbCreate(CompanyStruct Struct) throws CreateException { this.comId = struct.comId; //set the primary key setData(struct);//this removes some redundant code return null; } } 其余的代码比如getdata()和setdata()方法的实现和设计模式2中是完全一样的。
下一篇:软件设计:EJB设计模式2
为了避免设计模式1的缺点,我们介绍一下封装entity bean值域的value objec的概念。value object,用某些语言的术语来说,就是一个结构类型,因为他们 和corba的结构类型非常类似。 value Object code snippet for Company public class CompanyStruct implements java.io.Serializable { public Integer comId; //Primary Key public String comName; public String comDescription; public java.sql.Timestamp mutationDate; } ...[ 查看详情] |