コンバータ、ポピュ、ファサードとDTOこれらの概念SAP HYBRISは一緒に仕事する方法です

非常に重要な概念でHYBRIS。
問題はM HYBRIS MVCに対処する前に矛盾とDTOモデルDB層構造ながら、VショーDTO値としてDTO、JSPを指します。
その後、DB、DTOに書き込まれた変換、通過する必要があります後にデータを読み込みます。このロールの推移を実行し、コンバーター+ポピュです。

注:DTOは、ソフトウェア設計における一般的な概念であり、HYBRISは一意ではありません。定義されているようウィキ

HYBRIS公式の定義

(1)外観:ファサードは、基礎となる実装とオファーから抄録代替は、しばしば減少し、より複雑インタフェースことデザインパターンです。

(2)DTO:データ転送オブジェクト(DTO)のオブジェクトは値のみが含まれているとgetterメソッドとsetterメソッドを除いて一切のビジネス・ロジックを持たないために作成されます。DTOを使用して、あなたはHYBRIS項目を「組み合わせる」ことができます-たとえば、このドキュメントは、製品オブジェクトへ価格-メディア関連のデータを追加します。
先看CRMを。

永続データの方法で表示CDSからライン17を読み取ります。

このアナロジー。

可以看到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的原创文章,请关注公众号"汪子熙":

おすすめ

転載: www.cnblogs.com/sap-jerry/p/12153772.html