在設計模式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; }