EJB Design Patterns3(0分)

  • 主题发起人 主题发起人 VRGL
  • 开始时间 开始时间
V

VRGL

Unregistered / Unconfirmed
GUEST, unregistred user!
Design Pattern III
As we saw in Design Pattern II, there was a lot of code repetition in the Struct as
well as the Entity Bean with regard to declaring the fields (columns in the database).
Having the Entity Bean inherit from the Struct can eliminate this problem of code
redundancy. At this point, the Entity Bean(s) stilldo
not model the relationship
between them.
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;
}
The rest of the code in the Entity Bean, i.e. the getData() and setData()
methods, remains exactly the same as in Design Pattern II.
 
应杜宝的要求,贴出来,望大家指正。

设计模式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中
是完全一样的。
 
接受答案了.
 

Similar threads

I
回复
0
查看
3K
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
1K
import
I
I
回复
0
查看
615
import
I
I
回复
0
查看
3K
import
I
后退
顶部