首页 > 学院 > 开发设计 > 正文

EJB设计模式3

2019-11-18 12:36:25
字体:
来源:转载
供稿:网友

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

下一篇:EJB设计模式2

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表