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

查看:149
本文介绍了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.

无论如何,我都有一个带有Operation对象列表的实体类WorkOrder。

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.

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

But the most important are my 2 specific doubts:


  1. 我应该只有1个RFC来接收对WorkOrder实体(包括标头,操作)的所有更新吗?还是应该为每个操作创建1个RFC,一次只能处理一个操作?请记住,UI样机希望用户可以在单击SAVE按钮之前添加/删除多个操作,并且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 ).


推荐答案

最简单的解决方案永远是最好的( KISS YAGNI 原则)。创建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的功能模块。一个用于验证所维护的操作(尽可能进行验证),但这不应将任何内容保存到数据库中,另一个用于在用户单击SAVE按钮之后调用,以保存整个 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天全站免登陆