How to decide which one is Entity or Value Object ?

It can be easily identified by checking the required equality and by checking which one is immutable.
  • By checking types of equality required
    • Identifier equality: when two objects refer to same identifier.
    • Reference equality: when two objects refer to the same memory address.
    • Structural equality: when two objects refer to the same set of properties or attributes, means both objects can be interchangeable and don’t have any ID.
     

    Create entity where Identifier equality is required and create value object where structural equality is required. Always consider identifier and structural equality first before checking the referential equality as it can be required in both entity and value object.

  • By checking which one is immutable. Entities are mutable whereas Value objects are immutable.

Leave a Reply