本文介绍了工厂模式应该在哪里这个住在DDD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在辩论这一段时间,仍然没有得出一个结论。
虽然大多数例子我看到在应用层我倾向于认为它应该是在领域层的工厂代码。
原因:
我有时也初步验证我的工厂,我想对象的所有创作经历进行。
我想成为我的对象的所有实例化使用此代码。
有时一个操作需要哪些不自然的感觉传递给构造函数的参数信息。
和多了一些不是很重要的原因。

I have debated this for a while now and still have not come to a conclusion.While most examples I see have the factories code in the application layer I tend to think it should be in the domain layer.Reasons for this: I sometimes have initial validation done in my factory where I want all creation of objects to go through.I want this code to be used on all instantiates of my object.Sometimes an operation requires parameter information which feels unnatural to pass to a constructor.And a few more not as important reasons.

有没有原因,这是一个不好的做法?
这是否打破其他模式?

Are there reasons why this is a bad practice?Does this break other patterns?

推荐答案

+1做这件事。辅助功能将是一个很好的理由,我会保持造物代码至少接近域模型层。否则,领域模型的用户,将会得到根本困惑如何找到限制访问时,构造特殊实例化。其实一个声音理由分开这将是你有不同的有效方法创建同样的事情如它采用抽象工厂时,是通常情况下

+1 for doing that. Accessibility would be a good reason, I would keep the creational code at least close to the domain model layer. Otherwise users of the domain model will get simply confused how to instantiate it specially when finding restricted access constructors. Actually one sound reason to separate it would be that you have different valid ways to create the same thing e.g. which is the case usually when employing the Abstract Factory.

如果我不得不分开它,我把它放在如一个包(在Java中的情况下)至少域模型的相同水平,出货总是与它一起例如:

If I had to separate it I would put it in e.g. a package (in the case of Java) at least the same level of the domain model and ship it always along with it e.g.

upper
  --> domain
  --> domain_factory

这篇关于工厂模式应该在哪里这个住在DDD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 20:40