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?
jay.sf
  • 60,139
  • 8
  • 53
  • 110
Julian
  • 119
  • 6

1 Answers1

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).

SidMorad
  • 954
  • 12
  • 19