ddd - value objects to cover every property

好久不见. 提交于 2019-12-20 04:11:44

问题


Implementing an integration with a 3rd party system which exports products and imports orders from a web site.

There is some ddd work already done in the design and to continue it i would like.

Should every single property on the order and products be covered with a value object?

This would mean around 100 classes to cover all possible properties which seems excessive:

  • ProductSku
  • ProductName
  • ProductDescription
  • ProductPrice
  • etc...

回答1:


Should every single property on the order and products be covered with a value object?

They already are. The real question is whether you are going to leave that covering implicit, or make it explicit.

This would mean around 100 classes to cover all possible properties which seems excessive:

Oh, it has the potential to get much more tangled than that. ProductPrice, for example, encloses a concept of Money (which it has in common with ComputedTax and RoundedTax), which includes an Amount and a CurrencyCode to denote units).

You may want to give serious consideration to choosing a language in which creating hundreds of different value classes doesn't feel excessive.

See also:

  • https://fsharpforfunandprofit.com/posts/designing-with-types-making-illegal-states-unrepresentable/
  • http://blog.ploeh.dk/2016/11/28/easy-domain-modelling-with-types/



回答2:


Should every single property on the order and products be covered with a value object?

In any language that I know a primitive value is already a value object: immutable and without an identity (i.e. strings, numbers etc).

If you are referring to "Should I create a new class to encompass that data + behavior" then I say YAGNI. If you can't find a good reason to do it (you need strong typing, you make the implicit explicit etc) then don't do it right now. Wait until you will gonna need it.



来源:https://stackoverflow.com/questions/43162937/ddd-value-objects-to-cover-every-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!