Questions tagged [value-object]
47 questions
13
votes
4 answers
Is it really a bad practice to mock a POJO (value object) if you don't care about what it contains?
In the advice of Mockito about how to write good tests, it is written that we should not mock value objects (https://github.com/mockito/mockito/wiki/How-to-write-good-tests#dont-mock-value-objects). They even say
Because instantiating the object…

Ricola
- 269
- 1
- 3
- 7
10
votes
2 answers
Should well-known business ID of an entity be represented with a dedicated type in DDD/OOP?
In practical terms it means using an custom (immutable) class over a string or some other primitive type.
Examples:
Publishing: International Standard Book Number.
Finance: International Securities Identification Number.
Advantages:
Can ensure…

Den
- 4,827
- 2
- 32
- 48
8
votes
3 answers
In domain driven design, how do I convert a database table with a primary key into a Value Object?
Lets suppose there's a database schema defined like this:
Person.mail_address_key ----- Address.address_key
Person.billing_address_key ----- Address.address_key
A Person has a mailing address and a billing address. As a denormalization technique,…

Daniel Kaplan
- 6,776
- 5
- 32
- 46
7
votes
1 answer
Option functional type implementation and scenarios
Have you ever being implementing Option functional type? It is discussed here:
https://app.pluralsight.com/library/courses/tactical-design-patterns-dot-net-control-flow/table-of-contents
Basically it is about using IEnumerable with no or only…

Dmitry Nogin
- 450
- 4
- 11
7
votes
3 answers
C++ returning persistent objects
I'm currently trying to learn best practices in C++ after coming from a C# background. I understand that there are three ways of handling objects:
By value (objects are copied or moved when passed into and out of functions)
By reference
By shared…

innova
- 1,031
- 1
- 8
- 11
7
votes
1 answer
Unique Value Object vs Entity
Trying to convert some entities into value objects I am stuck in a case where what seems a value object must be unique within an aggregate.
Suppose we have a Movie entity which makes the root of an aggregate. This Movie entity is related with some…

SystematicFrank
- 897
- 8
- 18
6
votes
4 answers
Passing around large value objects vs converting to smaller value objects
Let's say I have a project that needs to do the following:
Multiple calls to read from the database where each call is a different query and returns back a value object (just has getters/setters). Let's say we end receiving 20 value objects
Perform…

radian
- 103
- 1
- 6
6
votes
4 answers
DDD and the persistence of value objects; must we denormalize?
I've been reading up a lot on Domain-Driven Development, and I came to the question of how to preserve lack of distinct identity with value objects (VOs). While in the DDD world, this is a requirement (yet I'm not sure I understand the full power of…

AdrianGW
- 71
- 1
- 3
5
votes
2 answers
Shouldn't Location be a Value Object?
Eric Evan's DDD book, Cargo Shipping Example, pg. 168:
Location
Two places with the same name are not the same. Latitude and longitude
could provide a unique key, but probably not a very practical one,
since those measurements are not of…

EdvRusj
- 623
- 6
- 12
4
votes
4 answers
Value/reference type, object and semantics
What are the relationships between these pairs of concepts:
value/reference type;
value/reference object;
value/reference semantics?
For the first pair of concepts, it seems to me that an object of value type is an element (data or procedure), and…

Géry Ogam
- 602
- 3
- 13
4
votes
1 answer
Use a custom value object or a Guid as an entity identifier in a distributed system?
tl;dr
I've been told that in domain-driven design, an identifier for an entity could be a custom value object, i.e. something other than Guid, string, int, etc. Can this really be advisable in a distributed system?
Long version
I will invent an…

Kazark
- 1,810
- 1
- 17
- 37
3
votes
2 answers
Is putting an Id to a value object a bad id?
I have a Customer which can have sereval address.
Sereval customers can possibily live at the same address.
So in my relational database a classic many to many relationship.
As :
An address can not change (a customer can change address);
It does…

Christophe Debove
- 207
- 2
- 7
3
votes
6 answers
How can I change my code to display information about failure of creation of a value object, when I want to process an array of such objects?
Consider class Crate that is a value object. Crate represents a valid 3-dimensional box.
In constructor I validate the given parameters, and I throw an exception, if supplied dimension parameters are invalid:
class Crate
{
protected $length,…

Dennis
- 8,157
- 5
- 36
- 68
3
votes
2 answers
How should blank/empty value objects be instantiated/structured?
I was wondering... what is considered the best practice to instantiate blank value objects? (in Java)
E.g. Assume we have some value object class Foo, that could be blank.
Would creating methods like these be a clean solution? (And perhaps adding in…

elimirks
- 275
- 2
- 3
- 9
2
votes
1 answer
Static validator in DDD value objects
I have a value object to hold a user id number as a string. This number has a unique format throughout my domain. So, it's being validated inside the object during instantiation and an exception is thrown if it's not of the correct format. The…

BlackPanther
- 131
- 6