R
R
Rasul2021-05-27 01:26:59
ASP.NET
Rasul, 2021-05-27 01:26:59

Entity vs Value Object DDD?

Hello! I am developing an application on asp.core to work with requests. I'm trying to apply DDD.
There is uncertainty in some decisions. I will try to briefly describe the entities.

There are two main aggregates `User` and `Ticket`
```
```

public class User
    {
        public UserId Id { get; private set; }
        public FullName FullName { get; private set; }
        public DateTime BirthDate { get; private set; }
        public Group Group { get; private set; }
        ...
    }

    public class Ticket
    {
        public TicketId { get; private set; }
        public Group Group { get; private set; }
        ...
    }


`Group` is a directory that is stored in another database and will be changed by another application. I made it as an Entity, contains Id and Name. In `User` this field specifies which group the user belongs to. The `Ticket` defines which group the ticket is assigned to. There are several such directories in `Ticket`.

Questions arose:

**1.**Is it correct that `Group` is an Entity? I thought to make it and other directories as ValueObject, but I read that it is not customary to store value objects in separate tables. And I need to store only the GroupId in the aggregates, in fact (in the database), so that after the change in the `Group` reference book, I can get the changed value in the aggregates.

**2.**If `Group` is still an Entity, how can I refer to it in two aggregates? Putting it in a separate unit seems wrong. As an option, I thought to create an Entity `TicketGroup` for `Ticket`, but in fact return the same data from one table through the repository

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2021-05-27
@RaSul909

1. The difference between VO and Entity is that it can be identified by Id. Also, the structure of VO does not change over time. For example, VO Email will be the same anywhere and its logic will not change for a long time.
2. It depends on how you use these Groups. If you need these groups somewhere in your application, then it is better to create them as a separate entity/aggregate. But you can also make them VO in the Ticket entity and store only the Group ID, or the group name itself. It all depends on how you deal with it in your context. For example, in the context of directories, Group can be an entity, and this is normal. And in the Ticket context, you can only store the ID or the value itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question