EJB设计模式3

在设计模式2中我们看到,在entitybean和struct之间
有很多重复的代码比如同样的字段声明(对应数据库中的表列)。
如果让entitybean从结构继承下来就可以避免冗余的代码。但是
这种设计,仍然不能显示beans之间的联系。

CodesnippetforCompanyEntityBean
publicclassCompanyBeanextendsCompanyStruct
implementsEntityBean{
EntityContextentityContext;
//allfieldsinCompanyStructareavailableforCMP
publicIntegerejbCreate(CompanyStructStruct)
throwsCreateException{
this.comId=struct.comId;//settheprimarykey
setData(struct);//thisremovessomeredundantcode
returnnull;
}

其余的代码比如getdata()和setdata()方法的实现和设计模式2中
是完全一样的。

你可能感兴趣的:(设计模式)