ABAP DDD 如何通过 RFC 从聚合中正确实现添加/更新/删除子项? [英] ABAP DDD how to correctly implement add/update/remove child from aggregate via RFC?

查看:39
本文介绍了ABAP DDD 如何通过 RFC 从聚合中正确实现添加/更新/删除子项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力为我当前的项目遵循 DDD 原则.不幸的是,由于技术限制,我必须使用 RFC,因此没有 OData 和 REST.这是一个很长的问题,我希望可以在 Stackoverflow 中提出这个问题.

I'm trying to follow DDD principles for my current project. Unfortunately I have to use RFCs due to technical constraints, so no OData and no REST. It's quite a long question I hope it's OK to ask this in Stackoverflow.

无论如何,我有一个实体类 WorkOrder,其中包含一个 Operation 对象列表.

In any case, I have an entity class WorkOrder with a list of Operation objects.

我有一个带有 SAVE 方法的 WorkOrderRepository 类,该类只接收一个 WorkOrder 对象,并且能够一次性保存所有内容(标题数据、地址等).无论是创建、更新还是删除.存储库对其余部分隐藏了 BAPI 调用.

I have a WorkOrderRepository class with a SAVE method that only receives a WorkOrder object and is able to save everything (header data, address, etc) in one go. No matter if it's creation, update or deleted. The repository hides the BAPI calls from the rest.

现在我想实现向工单对象添加/更新/删除操作的逻辑,即使我给方法的名称正确,我也不确定.也许他们应该插入/编辑/删除......我对此感到很困惑,因为在我看来他们在每个地方都使用不同的名称.

Now I want to implement the logic to add/update/remove Operations to the work order object and I'm not sure even if the names I give to the methods are correct. Maybe they should be insert/edit/delete... I'm quite confused with this since in every place I look they use different names.

但最重要的是我的两个具体疑问:

But the most important are my 2 specific doubts:

  1. 我是否应该只有 1 个 RFC 来接收 WorkOrder 实体的所有更新,包括标头、操作?或者我应该为每个操作创建 1 个 RFC,一次只处理一个操作?请记住,UI 模型希望用户可以在单击保存"按钮之前添加/删除多个操作,并且 RFC 具有隐式提交,而且据我所知,DDD 实体应始终在一次调用中更新.

选项 1:

FUNCTION ZWORKORDER_HDR_UPD
  IMPORTING
    VALUE(I_WORKORDER_ID) TYPE AUFNR
    VALUE(I_WORKORDER_HDR_CHG) TYPE ZWORKORDER_HDR_CHG
    VALUE(I_WORKORDER_HDR_UPD) TYPE ZWORKORDER_HDR_UPD "X structure for the BAPI
    VALUE(I_OPERATIONS_CHG) TYPE ZOPERATIONS_CHG
    VALUE(I_OPERATIONS_UPD) TYPE ZOPERATIONS_UPD
    VALUE(I_OPERATIONS_DEL) TYPE ZOPERATIONS_DEL
  EXPORTING
    VALUE(E_ERRORS) TYPE BAPIRET2_T.

选项 2

FUNCTION ZWORKORDER_OPERATION_CRT
  IMPORTING
    VALUE(I_WORKORDER_ID) TYPE AUFNR
    VALUE(I_OPERATION) TYPE ZOPERATION_CHG
  EXPORTING
    VALUE(E_ERRORS) TYPE BAPIRET2_T.

FUNCTION ZWORKORDER_OPERATION_UPD
  IMPORTING
    VALUE(I_WORKORDER_ID) TYPE AUFNR
    VALUE(I_OPERATION_CHG) TYPE ZOPERATION_CHG
    VALUE(I_OPERATION_UPD) TYPE ZOPERATION_UPD
  EXPORTING
    VALUE(E_ERRORS) TYPE BAPIRET2_T.

  FUNCTION ZWORKORDER_OPERATION_DEL
      IMPORTING
        VALUE(I_WORKORDER_ID) TYPE AUFNR
        VALUE(I_OPERATION_ID) TYPE ZOPERATION_ID
      EXPORTING
        VALUE(E_ERRORS) TYPE BAPIRET2_T.

  1. 我的 Workorder 方法应该如何处理这个问题?我对 update 方法特别困惑,因为我不确定我是否应该先获取现有操作,然后再更新它,还是让父类来做.但也许我的方法从根本上是完全错误的.

选项 1:

workorder->add_operation( i_operation ). "Pass flat structure from RFC? Or first create object?
workorder->update_operation( i_operation_chg
                             i_operation_upd ).
workorder->delete_operation( i_operation_id ).

选项 2:

workorder->add_operation( ).
operation = workorder->get_operation(i_operation_chg->get_id())
operation->update( i_operation_chg
                   i_operation_upd ).
operation->delete_operation( i_operation_id ).

推荐答案

最简单的解决方案总是最好的 (KISSYAGNI 原则).创建 1 个或 3 个支持 RFC 的功能模块并不重要,所以如果您可以用一个功能模块实现目标,那就用一个来实现.

The simplest solution is always the best (KISS and YAGNI principles). It doesn't really matter if you create 1 or 3 RFC-enabled function module, so if you can achieve your goal with one function module, then do it with one.

  1. 我认为你需要有两个支持 RFC 的功能模块.一个用于验证维护的操作(尽可能进行验证),但不应将任何内容保存到数据库中,另一个在用户单击保存"按钮后调用,以保存整个WorkOrder",包括维护的操作(此时也会有完整的验证).

  1. I think you need to have two RFC-enabled function modules. One to validate the maintained operations (do the validations as far as possible), but that should not save anything to the database, and another one called after the user clicks the SAVE button, to save the whole "WorkOrder", including the maintained operations (at this time, there will be the complete validation also).

如果你不需要为别的东西定义操作"类,现在,那么保持简单,不需要实例化一个对象.请注意,您可以创建一个带有私有静态方法的操作"类,并成为工作订单"类的朋友(只有该类可以使用操作类),只是为了更好地组织您的代码.

If you don't need to define an "operation" class for something else, right now, then keep it simple, no need to instantiate an object. Note that you may create an "operation" class with private static methods, and being a friend of the "workorder" class (only this class can use the operation class), just to organize better your code.

PS:虽然我不知道什么是领域驱动设计",但我不明白你的问题与它有什么关系,因为它只是看起来像简单的程序设计.

PS: although I don't know what is "Domain-Driven Design", I don't see how your question is related to it, because it just looks like simple program design.

这篇关于ABAP DDD 如何通过 RFC 从聚合中正确实现添加/更新/删除子项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆