2

I'm learning about Domain Driven Design and struggling with the question if a particular object should be handled as entity or value object.

All possible surname prefixes are kept in a database table. (The data is used in a combo box). Since there are records kept of all these prefixes, should Prefix be seen as an entity? Or is it still possible to handle it as a value object?

2 Answers 2

7

You already gave the answer yourself in your comment to the other question: If two Prefix objects with the same content are interchangeable, then Prefix is (probably) a value object.

Another rule of thumb is: "Domain first, infrastructure second", i.e., don't let infrastructure concerns (here: primary keys in database tables) influence your domain model.

-1

I thought the difference was the linkage with the database. So an Entity object has state that maintains its place in the DB, whereas a value object simply contains the data.

Writing the object back to the DB ends up as a update call in both cases, however the entity will use the internally-held key to refer back to the DB row, whereas the value object needs to get the key from its data... not much difference in practice ultimately!

I'd prefer a value object as I'm old-fashioned that way, I'd read only what was needed and update just that data. Less data and less state is always good.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.