将Doctrine与域驱动设计结合使用(Using Doctrine with Domain Driven Design)

编程入门 行业动态 更新时间:2024-10-27 08:28:03
将Doctrine与域驱动设计结合使用(Using Doctrine with Domain Driven Design)

我正在考虑实现域驱动设计方法(类似于此处描述的方法),但希望将其与Doctrine ORM集成。 做这样的事有没有人有成功?

我最初的本能是使用Doctrine作为DAO层,但是对于Doctrine来说,映射我的数据库字段似乎有点费解,而我的实体对象映射到(本质上)Doctrine对象上的同一组字段。

我最初的目标是将我的所有DQL /查询逻辑与我的域实体分开,但现在我感觉在设计模式领域有点迷失。

我知道Doctrine 2应该为DDD技术提供更友好的方法,但我不确定我是否要等那么久。 我想做的事情是否有意义,或者我应该找到另一种方法?

谢谢。

I'm thinking of implementing a Domain Driven Design approach (similar to the one described here), but want to integrate it with the Doctrine ORM. Has anyone had any success doing anything like this?

My initial instinct was to use Doctrine as the DAO layer, but it seems a a bit convoluted for Doctrine to map my database fields, and my entity objects map to (essentially) the same set of fields on the Doctrine object.

My original goal was to separate all my DQL/query logic from my domain Entities, but now I'm feeling a little lost in design-pattern land at the moment.

I know Doctrine 2 is supposed to provide a much more friendly approach to DDD techniques, but I'm not sure I want to wait that long. Does what I want to do make sense, or should I find another approach?

Thanks.

最满意答案

在我看来,由于缺乏Repository类,Doctrine对DDD来说并不完美。 Doctrine支持Table Data Gateway和Active Record等模式,虽然某些问题的良好模式不一定是“经典”DDD的最佳选择。 但是,您可以解决这些不足之处。

一种选择是从Doctrine_Table派生并将其用作穷人的存储库。 例如,如果你有一个名为'BlogPost'的类,你可能有一个表类'BlogPostTable',继承自Doctrine_Table。 然后,您可以将诸如“findByCategory”之类的方法添加到BlogPostTable类中,从而将这些逻辑与您的域对象(继承自Doctrine_Record)分开。 它与'纯'DDD倡导的模式并不完全相同,但它足够接近。

即使没有完全相同的设计模式,您仍然可以使用DDD的核心见解。 主要的是普遍存在的语言,即使用领域专家和开发人员都可读的精确语言来描述您的领域的概念。

Doctrine is, in my opinion, imperfect for DDD because of the lack of a Repository class. Doctrine supports patterns such as Table Data Gateway and Active Record which, whilst good patterns for certain problems, aren't necessarily the best choice for 'classic' DDD. You can, however, work around these deficiencies.

One option is to derive from Doctrine_Table and use that as a poor man's repository. For example, if you have a class called 'BlogPost', you might have a table class 'BlogPostTable', inheriting from Doctrine_Table. You can then add methods such as 'findByCategory' to the BlogPostTable class, keeping such logic separate from your domain objects (which inherit from Doctrine_Record). It's not exactly the same as the patterns advocated by 'pure' DDD, but it's close enough.

Even without the exact same design patterns, you can still use the central insights of DDD. The main one is the Ubiquitous Language, the concept of trying to describe your domain using precise language that is readable by domain experts and developers alike.

更多推荐

本文发布于:2023-07-25 10:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1259980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Domain   Doctrine   Design   Driven

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!