Marty Wallace
Marty Wallace

Reputation: 35754

ddd - value objects to cover every property

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:

Upvotes: 3

Views: 570

Answers (2)

Constantin Galbenu
Constantin Galbenu

Reputation: 17683

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.

Upvotes: 2

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57279

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:

Upvotes: 1

Related Questions