EJB設(shè)計模式3與設(shè)計模式2有什么不同?
印刷廠直印●彩頁1000張只需要69元●名片5元每盒-更多報價?聯(lián)系電話:138-1621-1622(微信同號)
??在設(shè)計模式2中我們看到,在entity bean和struct之間有很多重復(fù)的代碼比如同樣的字段聲明(對應(yīng)數(shù)據(jù)庫中的表列)。如果讓entity bean從結(jié)構(gòu)繼承下來就可以避免冗余的代碼。但是這種設(shè)計,仍然不能顯示beans之間的聯(lián)系。
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()方法的實現(xiàn)和設(shè)計模式2中是完全一樣的。