VOOZH about

URL: https://dev.to/saras_growth_space/lld-domain-modeling-value-objects-objects-defined-by-meaning-not-identity-84

⇱ LLD Domain Modeling: Value Objects (Objects Defined by Meaning, Not Identity) - DEV Community


In the previous post, we learned about Entities.

Entities are objects whose identity matters.

For example:

Order #123
Ride #567
Booking #ABC

Even if their data changes, they remain the same business object because their identity remains the same.

But not every object in a system behaves this way.

Some objects are important not because of who they are, but because of what they represent.

These are called:

Value Objects

Understanding the difference between Entities and Value Objects is one of the most important skills in Domain Modeling.


Start With a Simple Question

Imagine two money objects:

₹500

and

₹500

Do we care which specific ₹500 object it is?

No.

If the value is the same, they mean the same thing.

Now compare this with Orders:

Order #101
Order #102

Even if both have:

Amount = ₹500

they are still different orders.

Why?

Because identity matters.

This is the core distinction.


What Is a Value Object?

A Value Object is:

an object whose meaning comes entirely from its values, not from its identity.

If two value objects contain the same values:

they are considered equal.


Real-Life Example

Think about a postal address:

221B Baker Street
London
NW1

If two address objects contain exactly the same information:

they represent the same address.

Nobody asks:

Which Address object is this?

Instead they ask:

What address does it represent?

That makes Address a Value Object.


Entity vs Value Object

Consider this:

User

User #123

Identity matters.

Even if:

  • email changes
  • phone changes
  • address changes

it is still the same user.

Entity.


Address

Street
City
State
ZIP

Identity does not matter.

Only values matter.

Value Object.


The Quick Test

Whenever you encounter an object, ask:

If two instances contain exactly the same data, should the business consider them the same?

If YES:

Value Object

If NO:

Entity

Common Value Object Examples

Across real systems:

Money

₹500

Usually represented by:

  • amount
  • currency

Address

Street
City
Country
ZIP

Location

Latitude
Longitude

Coordinates

x
y

Time Range

Start Time
End Time

Distance

5 km

These are usually Value Objects.


Why Value Objects Matter

Many beginners model everything as entities.

Example:

AddressEntity
MoneyEntity
LocationEntity

This creates unnecessary complexity.

Because these objects do not need:

  • identity
  • lifecycle
  • tracking

They only need meaning.


Value Objects Make Models Simpler

Imagine an Order:

Without Value Objects:

Order
 street
 city
 state
 zip
 amount
 currency

The entity starts becoming cluttered.

With Value Objects:

Order
 Address
 Money

The model becomes:

  • cleaner
  • more expressive
  • easier to maintain

Value Objects Should Usually Be Immutable

This is one of their most important characteristics.

Suppose we have:

Money(500, INR)

Changing it into:

Money(1000, INR)

creates a completely different value.

Instead of modifying the existing object:

create a new one.

This prevents accidental side effects.


Why Immutability Helps

Imagine:

Address

being shared by multiple entities.

If someone changes it unexpectedly:

multiple objects may be affected.

Immutable value objects avoid this problem.

Their meaning never changes after creation.


Equality Works Differently

Entities:

Compare by identity

Value Objects:

Compare by values

Example:

Money(500, INR)

and

Money(500, INR)

should be equal.

Because their values are identical.


Ride Sharing Example

Consider Uber.

Ride:

Ride #567

Entity.


Pickup Location:

Latitude
Longitude

Value Object.


Fare:

Amount
Currency

Value Object.


Notice:

The Ride is tracked.

The Location and Fare simply describe the Ride.


Common Beginner Mistake

Treating every noun as an entity.

Example:

LocationEntity
PriceEntity
AddressEntity
DistanceEntity

This usually creates:

  • unnecessary IDs
  • unnecessary databases
  • unnecessary lifecycle management

Not everything needs identity.


Strong Domain Modeling Thinking

When designing a model:

Ask:

Does the business care who this object is,
or only what value it represents?

That single question often reveals whether you're looking at an Entity or a Value Object.


The Most Important Insight

Entities represent:

identity through time

Value Objects represent:

meaning through values

Understanding this distinction is one of the foundations of strong Low-Level Design.


One-Line Takeaway

A Value Object is an object whose meaning comes entirely from its values, making identity irrelevant and equality based solely on the data it contains.