SAP Hybris的Convertor, Populator, Facade和DTO這幾個概念是怎么協(xié)同工作的,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
創(chuàng)新互聯(lián)長期為數(shù)千家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為屏南企業(yè)提供專業(yè)的網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè),屏南網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
Hybris里極其重要的概念。
之前的issue談到了Hybris MVC里的M指的是DTO,JSP作為V顯示DTO的value,而DB層的Model和DTO的結(jié)構(gòu)不一致。
那么,數(shù)據(jù)從DB讀取之后,需要經(jīng)過一個轉(zhuǎn)換,寫入到DTO。執(zhí)行這個轉(zhuǎn)換的role,就是Convertor+Populator。
注:DTO是軟件設(shè)計里一個common的概念,不是Hybris特有。定義見[wiki](https://en.wikipedia.org/wiki/Data_transfer_object)
# 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之間的轉(zhuǎn)換非常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負責(zé)創(chuàng)建Data object的實例(就是Java class的實例), Populator負責(zé)call這個實例的setter方法把業(yè)務(wù)數(shù)據(jù)寫入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的實現(xiàn)一對比就清楚了。
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)的支持。
本文題目:SAPHybris的Convertor,Populator,Facade和DTO這幾個概念是怎么協(xié)同工作的
網(wǎng)站鏈接:http://jinyejixie.com/article12/psihdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、網(wǎng)站建設(shè)、域名注冊、App開發(fā)、營銷型網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)