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

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

image.png

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:


image.pngimage.png

可以看到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.


看具体的例子:


image.png

这个文件位置:

“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的实现一对比就清楚了。


目录
相关文章
|
2月前
|
开发框架 容器
SAP UI5 控件的 aggregation 的概念解析
SAP UI5 控件的 aggregation 的概念解析
|
2月前
|
应用服务中间件 Windows
129. SAP ABAP Update Process(更新进程)的概念和设计动机解析
129. SAP ABAP Update Process(更新进程)的概念和设计动机解析
什么是 SAP Hybris 中的 CMSLinkComponent
什么是 SAP Hybris 中的 CMSLinkComponent
|
9月前
|
存储 UED
SAP Hybris Revenue Cloud 和 SAP Subscription Billing 这两个产品的关联
SAP Hybris Revenue Cloud 和 SAP Subscription Billing 这两个产品的关联
|
2月前
|
安全 API 数据库
SAP ABAP OData 中 Function import 的概念介绍
SAP ABAP OData 中 Function import 的概念介绍
|
2月前
|
存储 供应链
什么是 SAP 产品主数据里的 Sales Unit 概念
什么是 SAP 产品主数据里的 Sales Unit 概念
|
2月前
|
应用服务中间件 调度 数据库
SAP ABAP Update Process(更新进程)的概念和设计动机解析试读版
SAP ABAP Update Process(更新进程)的概念和设计动机解析试读版
|
2月前
|
存储 安全 网络安全
SAP ABAP 系统 STRUST 事务码里 System PSE 的概念介绍
SAP ABAP 系统 STRUST 事务码里 System PSE 的概念介绍
|
2月前
|
数据库
SAP S/4HANA 系统的底层基石 - 通过实际的例子,介绍 CDS View 入门级的概念试读版
SAP S/4HANA 系统的底层基石 - 通过实际的例子,介绍 CDS View 入门级的概念试读版
SAP S/4HANA 系统的底层基石 - 通过实际的例子,介绍 CDS View 入门级的概念试读版
|
2月前
|
数据库 开发者 容器
SAP OData metadata.xml 里 EntityType,EntitySet 和 EntityContainer 三个概念之间的区别和联系
SAP OData metadata.xml 里 EntityType,EntitySet 和 EntityContainer 三个概念之间的区别和联系