Questions tagged [value-objects]

A value object is a fundamental concept of domain modeling in Domain-Driven Design.

A value object is a fundamental concept of domain modeling in Domain-Driven Design.

As defined by Eric Evans in his book, Domain-Driven Design: Tackling Complexity in the Heart of Software:

An object that represents a descriptive aspect of the domain with no conceptual identity is called a VALUE OBJECT. VALUE OBJECTS are instantiated to represent elements of the design that we care about only for what they are, not who or which they are.

324 questions
129
votes
9 answers

Value vs Entity objects (Domain Driven Design)

I have just started reading DDD. I am unable to completely grasp the concept of Entity vs Value objects.. Can someone please explain the problems (maintainability, performance.. etc) a system could face when a Value object is designed as a Entity…
StackUnderflow
78
votes
2 answers

How are Value Objects stored in the database?

I haven't really seen any examples, but I assume that they are saved inside the containing entity table within the database. Ie. If I have a Person entity/aggregate root and a corresponding Person table, if it had a Value Object called Address,…
kitsune
  • 11,516
  • 13
  • 57
  • 78
64
votes
13 answers

Is it okay to expose the state of an Immutable object?

Having come across the concept of immutable objects recently, I would like to know the best practices for controlling access to the state. Even though the object oriented part of my brain makes me want to cower in fear at the sight of public…
StickyCube
  • 1,721
  • 2
  • 17
  • 22
45
votes
6 answers

Value objects in DDD - Why immutable?

I don't get why value objects in DDD should be immutable, nor do I see how this is easily done. (I'm focusing on C# and Entity Framework, if that matters.) For example, let's consider the classic Address value object. If you needed to change "123…
Hobbes
  • 451
  • 1
  • 4
  • 4
45
votes
11 answers

Value objects vs associative arrays in PHP

(This question uses PHP as context but isn't restricted to PHP only. e.g. Any language with built in hash is also relevant) Let's look at this example (PHP): function makeAFredUsingAssoc() { return array( 'id'=>1337, …
kizzx2
  • 18,775
  • 14
  • 76
  • 83
42
votes
5 answers

Value Objects in CQRS - where to use

Let's say we have CQRS-inspired architecture, with components such as Commands, Domain Model, Domain Events, Read Model DTOs. Of course, we can use Value Objects in our Domain Model. My question is, should they also be used…
driushkin
  • 3,531
  • 1
  • 24
  • 25
20
votes
7 answers

Is a Data Transfer Object the same as a Value Object?

Is a Data Transfer Object the same as a Value Object or are they different? If they are different then where should we use a DTO and where should we use a VO? The programming language we are talking about is Java and the context is - there is a web…
20
votes
2 answers

Inheritance on doctrine's embeddables

Is it possible to use inheritance on value objects embedded in doctrine entities? The situation I'm thinking about is: I have an entity that has and embedded value object. That value object has the following hierarchy: class myEntity { /**…
AntonioHS
  • 1,360
  • 10
  • 25
17
votes
6 answers

DDD, value objects and ORM

Value objects do not have identity. ORM needs identity to update the database. How to trick ORM? (Marking Id for value object as internal won't work because ORM lives in a different assembly and moving it to the same assembly is not…
Arnis Lapsa
  • 45,880
  • 29
  • 115
  • 195
16
votes
3 answers

In DDD, what are the actual advantages of value objects?

I have gotten so far that I understand entity objects have an ID while value object have not, but in the most common example you have the person entity that have a address value object attached to it. What is the big advantage of creating a separate…
terjetyl
  • 9,497
  • 4
  • 54
  • 72
14
votes
3 answers

DDD: Using Value Objects inside controllers?

When you receive arguments in string format from the UI inside you controller, do you pass strings to application service (or to command) directly ? Or, do you create value objects from the strings inside the controller ? new Command(new…
resehuvija
  • 201
  • 2
  • 7
13
votes
2 answers

Entity Framework Core: Fail to update Entity with nested value objects

I have an entity that has a value object and this value object has another value object. My issue is that when updating the entity along with the value objects, the entity with the parent value object get updated but the child value object…
13
votes
2 answers

Declare Doctrine Embeddable as nullable or not

Let's say I've got two Doctrine entities, Person and Company. Both have an address field which accepts an Address value object. As per business rules, Company::Address is required while Person::Address can be null. Doctrine 2.5 proposes the…
marcv
  • 1,874
  • 4
  • 24
  • 45
13
votes
3 answers

How value objects are saved and loaded?

Since there aren no respositories for value objects. How can I load all value objects? Suppose we are modeling a blog application and we have this classes: Post (Entity) Comment (Value object) Tag (Value object) PostsRespository (Respository) I…
yeraycaballero
  • 1,603
  • 3
  • 19
  • 29
13
votes
3 answers

DDD class design dilemma with Value Objects with DB id and Entities

This is a long question so i am gonna go straight to the point. This is pseudo code for better illustration of the problem DB Structure User (UserID, Name, LastName) Address(AddressID, UserID, Street, City, State, ZipCode) =>Many to One User…
Pepito Fernandez
  • 2,352
  • 6
  • 32
  • 47
1
2 3
21 22