0

How to differentiate Entity and ValueObject?

For my recent project using DDD, I am often confused by the two.

  1. What's Entity and VO?
  2. The responsibility
  3. Should Entity and VO contain any logics, like date parsing, returning a bool by the fields?
6
  • 1
    stackoverflow.com/q/75446/2575224 Commented May 21, 2018 at 8:31
  • thanks for you comment Commented May 21, 2018 at 10:16
  • 1
    You are welcome. The difference between the two of them is largely discussed on the internet. Commented May 21, 2018 at 10:18
  • Well...haha. Although largely discussed on the internet, most of them are about the theory. You know how abstract is DDD. In the reality, we may come across varied issues. If we could get a wiki about best practice for DDD, that should help a lot Commented May 28, 2018 at 2:57
  • I know, practicing DDD is a different Beast. The only solution is, well, more practicing :) I read a lot of books and articles and what helped me was to actually write code. Commented May 28, 2018 at 6:55

1 Answer 1

0

I also wish it was an easy way of rule of thumb for determining if your new model is Entity or ValueObject?

Personally I am using following question:

  • Do I have any property in my model that history of it's changes matters?

    • if yes then my model is more likely an Entity
    • if no then my model is more likely a ValueObject

So using it in example, Person model depends to our domain(logic/bussiness), history of it's FirstName property may matters or not. if it does then Person is Entity.

In the other hand we must be able to set updatable = false for our ValueObject properties. and when update is necessary, simply we be able to delete previous record and insert new one[1].

About your other questions, I think one of the greatest thing about DDD is isolating logic into domain/model layer. "Simple POJOs which are easily testable". So feel free to add any logic into your domain/model as far as you can unit-test them with easy.

I hope my answer was some kind of useful and please let me know if you find something more convenient for distinguishing these two guys! :^)

[1] If ValueObject is in many-side of a relation, then we need to check if update is necessary for all (one-side)references or not. if not then we leave current record as it is and we insert new record(for those references that update is needed).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.