【正文】
type Engineer 。 ? 低效 ,需到 theSuperPart節(jié)點的所有組件中尋找self 第 III種冗余組合模式 type product is body [… super: Product; sub: ProductSet; … ] end type product ? 該模式的使用中,重要的是維護 DB的一致性 N:M關系舉例 Engineers Products designs ? 方式一 ,采用組合的冗余表達方式 type Engineer is type Product is body body […… […… designs: ProductSet。 !!we could already exit the loop here return isUsed。 ? 高效,只需沿 self向上查找到根一條路徑 –采用結(jié)構(gòu) II define isPartOf(theSuperPart) is var isUsed: bool := false。 return false。 while ( part != NULL ) If ( part = theSuperPart ) return true。 ? 該程序是高效的。 !!recursive call of partList return resultSet。 ( self )。 !!recursive call of partList return resultSet end define partList –采用結(jié)構(gòu) II define partList is var resultSet: ProductSet。 !!create an empty set ( self )。 適用范圍:查找組成某部件的所有子部件 Sub:{} Sub:{} Sub:{} Sub:{} Sub:{} Sub:{} Sub:{} Sub:{} 應用示例 ? 操作 partlist:輸出組成某個產(chǎn)品的所有部件 – 采用結(jié)構(gòu) I define partList is var resultSet: ProductSet。 ……] end type Product 。 適用范圍:查找某種產(chǎn)品被組裝在什么部件中。 遞歸的 1:N的關系 ? 產(chǎn)品與產(chǎn)品間具有遞歸的組合聯(lián)系 ? ER圖的展開可以有兩種描述模式 products position N 1 Sub Super ? A:通過 Super屬性 —表達了 系: 即:一個產(chǎn)品屬于上層產(chǎn)品的一個部件 type Product is body […… super: Product 。 end define hire。 ? Fire define fire(badEng) is Begin (badEng)。 := self。 type EngineerSet is body {Engineer} end type EngineerSet。 ……] ……] end type Engineer 。 示例分析 (二 ) ? 工程師與部門間的 1:N的聯(lián)系 type Engineer is type Division is body body […… […… worksfor: Division。 newResidence. isOccupiedBy := self。 if ( != NULL ) := NULL。 (4) := leonardo。 (2)If ( != NULL ) . isOccupiedby :=NULL。 end type Office。 isOccupied: Engineer。 … ak: TkR。 … entitiyn: Tn。 ? 為了檢索高效率 ,需要考慮受控的冗余建模。 := Ok 。 := O1。 implementation define initTR(Oleft ,Oright,O1,…,O k) is begin := Oleft。 … ak: TkR。 right: Tright。 end type TR 。] end type Tleft。 [left: Tleft 。 –對 (1),必須重新定義 R屬性的值接受操作 –對 (3),必須對 TR的對象實例庫進行一致性維護 ,即 TR的 insert操作進行一致性維護 N:M的二元聯(lián)