EJB设计模式3 (转)[@more@]
在设计模式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中
是完全一样的。
设计 模式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中
是完全一样的。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-990175/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10752043/viewspace-990175/
本文探讨了EJB设计模式的改进方案,通过让Entity Bean继承结构类来减少代码冗余,并讨论了如何通过这种方式更好地展示beans之间的联系。
1938

被折叠的 条评论
为什么被折叠?



