7

大佬们好,落地 DDD 时有两个迷惑我的问题, application 可以互相调用吗?调用 RPC...

 3 years ago
source link: https://www.v2ex.com/t/805368
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

大佬们好,在落地 DDD 中遇到了两个问题,感激不尽~

  1. 项目中要用 http 调用外部的订单服务 rpc,取回来之后本有一些值要做逻辑转换处理,需要创建与之对应的领域 OrderDomain 吗?如果没有领域,那么 application 层就要做这逻辑,似乎违背了高内聚?还是说封装一个请求此 rpc 的方法,然后做一些逻辑转换即可?

  2. application 可以互相调用吗?举例如下(不用太纠结例子的合理性,主要想表达重复逻辑相互调用的问题)

    //伪代码,假设购物车,和订单是两个领域
    class OrderApplicationService {
        create(List<Integer> productIds) {
            //调用订单领域创建订单
            orderDomainService.create();
            
            //调用购物车领域删除商品
            buyCarDomainService.delete();
        }
    
    }
    

    后面出现了另一个需求比如优惠一键购买之类(只是个例子),这里同样有创建订单的逻辑,可直接调用吗?还是说再提一个 facede 层,来组合两个 application 层的方法?那如果后面 facede 层又存在相同逻辑要调用呢.....

    class BuyCombinationApplicationService(Integer relationId) {
    	//获取组合商品信息
        	List<Integer> productIds = productDomainService.getListByRelationId();
        
    	//下面的逻辑和上面的 OrderApplicationService.create 一致
    	//调用订单领域创建订单
    	orderDomainService.create();
    	//调用购物车领域删除商品
    	buyCarDomainService.delete();
    } 
    

期待你的回复~


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK