价值对象的业务逻辑

发布于 2025-01-24 08:20:07 字数 379 浏览 2 评论 0原文

我认为价值对象不应该具有业务逻辑。

也许让其他程序员感到困惑。

对于Exmaple,

public class PersonVO {

    private String name;
    private int age;

    public void somethingBusinessLogic() {
        // Do very complecated logic -> Using Reflection, Conversion
    }
    
}

如果我使用此vo,则必须查看vo逻辑如何工作。

许多程序员将其业务逻辑放在VO中。

我想知道什么是最佳实践?

I think value object should not have business logic.

That maybe confused other programmers.

for exmaple,

public class PersonVO {

    private String name;
    private int age;

    public void somethingBusinessLogic() {
        // Do very complecated logic -> Using Reflection, Conversion
    }
    
}

If i use this VO, have to look vo logic how to work.

many of programmers put their business logic inside of VO.

I wonder what is best practice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又爬满兰若 2025-01-31 08:20:07

这取决于您在应用程序中使用的架构。如果您已经进行了分层体系结构:

  • 服务层应该具有业务逻辑
  • 数据层负责CRUD操作,则该层应该非常简单。除基本CRUD逻辑外,该图层不应具有任何逻辑。模型类不应具有任何逻辑,因为ORM阻止您在模型类中具有逻辑。
  • UI层应仅对演示和处理DTO或ViewModels负责,

请阅读更多有关在这个美丽的答案中

It depends on what architecture you are using in application. If you have layered architecture:

  • Service layer should have business logic
  • Data layer is responsible for CRUD operation and this layer should be very simple. This layer should not have any logic, except base CRUD logic. Model classes should not have any logic as ORM prevents you from having logic in model classes.
  • UI layer should be responsible only for presentation and deal with DTOs or ViewModels

Read more about other architectures here in this beautiful answer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文