douhan1860 2014-08-26 16:36
浏览 37

构建器中的值对象

When I am writing a builder, if the entity I am building contains value objects, what is the best way to deal with that?

Should I have a method called something like With_MyvalueObject(IMyValueObject $vo) and simply set the VO that way - obviously this technique requires that the value object exists first so I can pass it as an argument. Or should I make basic than that and take in values to create the value object within the builder?

  • 写回答

1条回答 默认 最新

  • doukan4795 2014-08-27 08:53
    关注

    Either way will be fine. I'm personally passing value objects to factories/builders as it's more concise.

    Anyway I'm trying to map things as close to UL(ubiquitous language) as I can, so if it wouldn't be a builder, but in example method user.commentOnPost, then I pass basic values since existing of comment has no sense until user comments on something. So instead of doing:

    comment = Comment(text, author, post)
    commentRepository.save(comment)
    

    I do:

    user.commentOnPost(text, post)
    

    Internally it creates comment in the same way as above, but it is created when user actually is commenting, not before, so it makes more sense.

    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备