简体   繁体   English

如何删除值对象中的值对象 [DDD]

[英]How to remove Value Object within Value Object [DDD]

I have a question regarding DDD.我有一个关于 DDD 的问题。 How do I remove a VO in a VO ?如何删除 VO 中的 VO ? So I have aggregate x with a VO y.所以我有一个 VO y 的聚合 x。 In VO y there is a list of VO z.在 VO y 中有一个 VO z 的列表。 zListVO列表VO

Now I want to remove a zVO from the aggregate.现在我想从聚合中删除一个 zVO。

Can i do : (method in application layer)我可以做:(应用层中的方法)

public void main 
{
  y.remove(zVO z)
}

AGGREGATE X聚合 X

private void Handle(RemovedZDE z)
{
    this.x.remove(z.z);
}

And then make a method in VO Y where I remove z from their list of VO ?然后在 VO Y 中创建一个方法,我从他们的 VO 列表中删除 z ?

Class yVO yVO级

protected void Remove(zVO z)
{
  zListVO.remove(z);
}

Typically, instances of the value object pattern are immutable;通常,值对象模式的实例是不可变的; you don't typically have commands (in the CQS sense), just queries.您通常没有命令(在CQS意义上),只有查询。

Therefore, it is more common to see something like因此,更常见的是看到类似的东西

new_y = old_y.remove(z)

I have aggregate x with a VO y.我有一个 VO y 的聚合 x。 In VO y there is a list of VO z.在 VO y 中有一个 VO z 的列表。 zListVO列表VO

The basic idea is going to look like:基本思想将如下所示:

X::remove(Z z) {
   old_y = this.y
   new_y = old_y.remove(z)

   // X is an entity, so we normally update its state directly
   this.y = new_y
}

Y::remove(Z z) {
    old_list = y.zListVO
    new_list = old_list.remove(z)
    // Y is a value, so we create a new value to describe
    // the change
    return new Y(new_list)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM