日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SAP Hybris的Convertor, Populator, Facade和DTO这几个概念是如何协同工作的

發布時間:2023/12/19 编程问答 64 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SAP Hybris的Convertor, Populator, Facade和DTO这几个概念是如何协同工作的 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Hybris里極其重要的概念。
之前的issue談到了Hybris MVC里的M指的是DTO,JSP作為V顯示DTO的value,而DB層的Model和DTO的結構不一致。
那么,數據從DB讀取之后,需要經過一個轉換,寫入到DTO。執行這個轉換的role,就是Convertor+Populator。

注:DTO是軟件設計里一個common的概念,不是Hybris特有。定義見wiki

Hybris官方定義

(1) Facade: A facade is a software design pattern that abstracts from an underlying implementation and offers an alternate, often reduced and less complex interface.
(2) DTO:Data Transfer Objects (DTOs) are objects created to only contain values and have no business logic except for getter and setter methods. Using DTOs, you can “combine” Hybris items - for example, this document adds price- and media-related data to a product object.
先看CRM。

line 17的方法從CDS view里讀取persistent data:

這樣做類比。

可以看到CRM兩個layer之間的轉換非常light weight,僅僅是幾個賦值操作。
Hybris里把這個賦值操作封裝到了兩個新的object里:Converter和Populator。
為什么要搞這么麻煩:

(1) Data objects are constructed from Models or other Service Layer objects using Converters and Populators. The Data object is always created from a prototype-scoped spring bean that is defined in the beans.xml file for the extension.
(2) Converters create new instances of Data objects and call Populators to populate these.
即Converter負責創建Data object的實例(就是Java class的實例), Populator負責call這個實例的setter方法把業務數據寫入data obeject,這樣JSP綁定到這些data object的某個屬性的field就能顯示出來值。

既然Hybris基于Spring,那么也要follow Spring的一些原則:

(1) No concrete Converters should be written, all converters should be Spring configured only and should use the AbstractConverter base class.
(2) No Populator should be called directly in code, Converters should be Spring injected and used.
(3) All conversion logic should exist in Populators and these should be well-encapsulated and independent.

Populators

Populators break the conversion process of filling out a Data Object down into a pipeline of population tasks or steps. Each Populator carries out one or more related updates to the Data Object prototype. Each population step can invoke services or copy data from the source business object to the prototype Facade Data object. Facades always use a Converter to create a new instance of a Data Object prototype and then invoke Populators or other Converters to fulfill the task of building up the Data Object.

看具體的例子:

這個文件位置:
“C:\Hybris\6.5.0.0.23546\hybris\bin\ext-accelerator\acceleratorservices\src\de\hybris\platform\acceleratorservices\payment\cybersource\converters\populators\PaymentDataPopulator.java”

為什么要單獨抽象這兩個object出來?和CRM Genil layer的實現一對比就清楚了。

要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":

總結

以上是生活随笔為你收集整理的SAP Hybris的Convertor, Populator, Facade和DTO这几个概念是如何协同工作的的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。