douzhong5902 2016-09-15 01:28
浏览 64

依赖模块的Golang DDD实现

I'm trying to implement DDD architecture to my application modules and get stuck with a problem of storing similar(depending) structures between them.

In the first package I store everything that is related to entity People: Services(Repositories), Controllers, Models, etc...

In the second package I store everything that is related to another entity Apartments: Services(Repositories), Controllers, Models, etc...

Each Apartment can contain multiple Tenants which are stored in database as the same structure as People.

Some Apartment package services should be able to call methods like get/update/... Tenants. I would gladly not re-implement these actions and use them from the implementations in the People package PeopleService, but that service returns People entity, not the Tenant.

Should I create additional structure (copy-paste whole source code) of People into the Apartment package, call it Tenant and convert return types of PeopleService to it?

Or is there another way to do it?

Also, where should I store interfaces of services/repositories(interfaces with CRUD-like methods) of concrete entity? Should interface PeopleService be both in People and Apartment packages?

Thanks.

  • 写回答

1条回答 默认 最新

  • dqyknf4423 2016-09-15 08:58
    关注

    There could be different approaches and frankly the question probably should be closed as too broad & opinion based.

    I probably would do it this way:

    1. Decouple all linked models in a separate packages models.

    2. Use composition for People->Tenants, e.g. type Person { Name string } type Tenant struct { Person }

    3. Regards People<->Apartments - create a package tenants that will operate with models & services of people & apartments.
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等