Value Object是不好的模式吗? [英] Is Value Object a bad pattern?

查看:104
本文介绍了Value Object是不好的模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用VO(POCO)是不好的设计模式吗?有些人说,一个对象的所有领域逻辑都需要在该对象中。



例如:ProductVO:Id,Name,Description



ProductBO:SearchById(int id),Insert(ProductVO newProduct),Update(ProductVO updatedProduct,SearchByKeyword(string word)......

解决方案

所有域逻辑都应该在域对象中的域中,但是有一个强有力的论据被认为是技术问题,比如如何将对象保存到数据库或日志对象活动,不是域行为,它们是基础架构或应用程序问题,不应在域对象中。



检查域驱动设计,在这种方法中,建议您将持久性逻辑(如持久化/获取对象)的域相关方面分为独立的类型(也称为域层),称为存储库...但即使在这里,技术方面如何与数据库进行交谈?持久性存储技术被划分为基础设施服务。



一种查看方式是服务应分为三组,




  • Infrsastructure Services。与通用技术方面有关的那些
    (如通用数据库访问,缓存,日志记录,配置,消息传递等)


  • 应用程序服务。这涉及与业务领域无关的技术或应用程序设计方面(UI中的MVC模式,屏幕导航,域实体初始化方法等。


  • 域名服务。与业务模式明确相关的服务(例如,为特定航班上的航空公司座位创建预订,特定膳食请求和座位分配以及指定信用卡的适当交易借项) )



    最后一种类型的服务应该在域图层中,前两个,而不是...



Is use of VO´s (POCO) a bad design pattern? Some people say that all domain logic of an object needs to be together in that object.

Ex.: ProductVO: Id, Name, Description

ProductBO: SearchById(int id), Insert(ProductVO newProduct), Update(ProductVO updatedProduct, SearchByKeyword(string word)......

解决方案

All Domain logic should be in the Domain layer, in Domain Objects... but there is a strong argument to be made that technical concerns, like how to save an object to the database, or log an objects activities, are not domain behaviors, they are infrastructure, or application concerns, and should NOT be in the domain objects...

Examine Domain Driven Design, In this methodology, it is recommended that you separate Domain-related aspects of persistence logic (like persisting/Fetching objects) into a separate Type (also in the Domain Layer) called a Repository... But even here, the technical aspects of how to talk to a database or other persistence storage technology are furthur separated into an infrastructure service.

One way to look at this is that services should be partitioned into three sets,

  • Infrsastructure Services. those that relate to general technical aspects (like generic database access, caching, logging, configuration, messaging, etc.)

  • Application services. That relate to technical or application design aspects that have nothing to do with the business domain (MVC pattern in UI, Screen navigation, domain entity initialization methodology, etc.

  • Domain Services. Services that are explicitly related to the business model. (for example, creating a reservation for a airline seat on a specific flight, with specific meal requests and seat assignment, and appropriate transactional debits to a specified credit card...)

    The last type of "service" should be in the Domain Layer, the first two, - not...

这篇关于Value Object是不好的模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆