EJB设计模式3

王朝java/jsp·作者佚名  2006-01-08
宽屏版  字体: |||超大  

设计模式3

在设计模式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中

是完全一样的。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有