Domain code development, SOC and object identification

I tried to ponder DDD and how this might relate to MVC, but I am having problems identifying the entity.

In particular, I try to maintain a strict separation between the presentation, domain, and data models. My hovering here is how I maintain the identification of an object across these boundaries. To clarify, I use separate classes to represent the same object in different contexts - for example, I have a ShipmentRequest domain class, several ShipmentRequestView presentation classes (depending on the properties needed for a particular view), and a data table "shipment_request" (my data model).

It seems to me that using the ID property (for example, ShipmentRequestId) will be a violation of the separation that I am trying to achieve, since this ID property is a database problem, not a problem for the domain; and I don’t want to transfer the same object between layers, as that would mean transferring unnecessary data to my presentation layer.

How to maintain this separation and still track the identity between these layers?

+6
mapping domain-driven-design separation-of-concerns
source share
3 answers

Without the Id field in your entity, you cannot match it with a database row. Therefore, this id field, even if it has nothing to do with your objects, should flow in your domain model.

I feel that it’s most common to use a presentation model, especially if what you are trying to achieve hides some properties.

I think that the separation of problems is mainly due to the limited context. For example, your Person, PersonView, and Person table all seem to refer to a transaction processing context. In this context, I would not even have a PersonView, and the character table would be abstracted.

On the other hand, if you are in the context of reporting, PersonView will be more useful.

I think the context is much more important than any layering scheme.

As for the lack of a natural key in your personality, this may mean that Man is not an entity. For example, in any real-life application, there is always a number associated with a person: an employee has an employee number, a client as an account number, etc. This business identifier is definitely part of the domain.

+2
source share

I think that the presence of the “ID” field on entities is a concession that many (most?) People ultimately make, and I would not feel guilty for that.

As you say, even if you are not dealing with a database, you still need the concept of personality. You can try to find some kind of “natural” identity for each entity (a field, for example a name or a combination of several fields), but this is not always possible. Even when this is the case, the presence of an identifier field often acts as a convenient short form for the expression "an entity whose name is X and whose birth date is Y, and SSN is Z".

In the end, although perhaps less “clean,” having an ID field is likely to simplify a lot.

+1
source share

A send request is by far the best example!

How will users find a shipment request? Depending on the answer, you may need an identifier that users can remember, for example, 20091012-A.

Can I change the ID of a shipment request? If not, use the db key for identification.

Will you need to transfer send requests from one system to another? If yes, do not use the db key for identification.

Whatever key you use, you will need to make it available in the presentation model so that you can create links to actions for a specific sending request.

+1
source share

All Articles