Association, Composition and Aggregation in UI5, CRM, S/4HANA and C4C

i042416發表於2018-04-06

UI5

UI5使用Association和Aggregation描述控制元件之間的關係。

Aggregation:parent和子控制元件在lifecycle上存在依賴關係:

When a ManagedObject is destroyed, all aggregated objects are destroyed as well and the object itself is removed from its parent. That is, aggregations won't contain destroyed objects or null/undefined.

比如UI5的轉盤控制元件Carousel: 一旦轉盤被析構,裡面顯示的page當然也沒有繼續存在的意義了,需要跟著被析構。

Association, Composition and Aggregation in UI5, CRM, S/4HANA and C4C

而Association描述了在lifecycle層面的一種soft dependency關係:

Managed associations also form a relationship between objects, but they don't define a lifecycle for the associated objects. They even can 'break' in the sense that an associated object might have been destroyed already although it is still referenced in an association.

最明顯的例子就是控制元件和其label的關係,比如button和label:技術上來說,可以彼此分開獨立存在。

Association, Composition and Aggregation in UI5, CRM, S/4HANA and C4C

CRM

CRM的Genil model存在三種型別的relation,可以在doman CRM_RELATION_KIND裡檢視:

Association, Composition and Aggregation in UI5, CRM, S/4HANA and C4C
Association, Composition and Aggregation in UI5, CRM, S/4HANA and C4C

區別:

  • Association: Link between any kind of objects. Can also be defined across components with root or access object as target. 依賴關係最為loose的一種relation,可以用來連線跨model之間的節點。

  • Aggregation: Binds child objects to a root object. Only access and dependent objects can be aggregated. 只適用於同一模型的節點之間的關聯。

  • Composition: Like an aggregation, but composed child objects always exist. 特殊型別的Aggregation。目標節點的Cardinality為1或者1..n

S/4HANA

只有兩種:association或者composition。Composition的含義同CRM裡的aggregation,而association的含義同UI5和CRM中的association一致。

Association, Composition and Aggregation in UI5, CRM, S/4HANA and C4C

C4C

只有兩種: association或者composition。C4C的這兩種relation多了一個限制:relation的目標BO必須和源BO在同一個部署單元Deployment Unit,或者目標BO位於Foundation部署單元內。

Association的語法如下圖:

Association, Composition and Aggregation in UI5, CRM, S/4HANA and C4C

association的multiplicity只支援[0,1]或者[1,1], 如果不顯式指定,預設為[1,1].

C4C relation的一個特色是,一旦申明瞭一個子節點之後,系統會預設生成一個對應的composition。

下圖第4行程式碼會自動生成一個[0,n]的從root節點到Item節點的composition。

Association, Composition and Aggregation in UI5, CRM, S/4HANA and C4C

要獲取更多Jerry的原創技術文章,請關注公眾號"汪子熙"或者掃描下面二維碼:

Association, Composition and Aggregation in UI5, CRM, S/4HANA and C4C
Association, Composition and Aggregation in UI5, CRM, S/4HANA and C4C

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2152635/,如需轉載,請註明出處,否則將追究法律責任。

相關文章