Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should value object hold reference to entity?

Tags:

Should value object hold reference to entity in DDD methodology?

EDIT

@Dmitry:

This is probably my case. Here I attach class diagram where the Account hold references to collection of IInvoiceable items. I treat with Tenant as entity, but it owns only 1 account and i dont think that Account needs identity. its part of Tenant. Or should I treat it as Entity? To me it doesnt make sense.

enter image description here

like image 698
Ivan Avatar asked Feb 29 '12 11:02

Ivan


People also ask

Can a value object reference an Entity?

A value object can reference other entities. For example, in an application that generates a route that describes how to get from one point to another, that route would be a value object.

What is the difference between an Entity and a value object?

In terms of immutability, the difference between entities and value object is that value objects are immutable, whereas entities are almost always mutable. You don't modify a value object; instead, you create a new one and replace the old instance with it.

What is the purpose of value objects?

Value Objects can be especially useful as a means for describing concepts in an application that have intrinsic rules but which are not themselves entities. In many applications, some concepts that are described as entities would be better off implemented as value objects.

Is an Entity which store a value?

The main difference between entities and value objects lies in the way we compare their instances to each other. The concept of identifier equality refers to entities, whereas the concept of structural equality - to value objects. In other words, entities possess inherent identity while value objects don't.


1 Answers

Yes it can. This would be a relatively obscure case but DDD allows for it and it can be useful. From the DDD book by Eric Evans:

VALUE OBJECTS can even reference ENTITIES. For example, if I ask an online map service for a scenic driving route from San Francisco to Los Angeles, it might derive a Route object linking L.A. and San Francisco via the Pacific Coast Highway. That Route object would be a VALUE, even though the three objects it references (two cities and a highway) are all ENTITIES.

page #98

like image 191
Dmitry Avatar answered Sep 22 '22 17:09

Dmitry