Domain Driven Design : Entities
Tags: ddd, software
Published: 2022-01-22 10:30:36

Hello Folks , Today we are going to tals about Entities in Domain Driven Design , i will not go deep , just few questions where the responses are found in [This Book](https://www.amazon.fr/Implementing-Domain-Driven-Design-Vaughn-Vernon/dp/0321834577) :smiley:



# What is an Entity 
Firstly when i cam into this , i thought that it was an entity like in java programming language :flushed: but in fact it is much deeper than that , i will give you the quote from Vaugh Vernon : 
>An Entity is a unique thing and is capable of being changed
continuously over a long period of time. Changes may be so extensive that the object might seem much different from what it once was. Yet, it is the same object by identity.


:weary: what does it means ? it means that whatever you modify on that Entity , it remains the same because of that _Unique Identity_. Like us humans , whatever we are going to do or change on us , our DNA remains the same , it is our unique Identity . In the Software that is the world we humans are the entities of this world.


So the question is now , How To Create That Unique Identity for our entities ? :eyes:


# Unique Identity Generation Patterns 
Yes there are three mains methods for the generation of Unique Identity 

1. User Provides Identity
2. Application Generates Identity
3. Persistence Mechanism Generates Identity



# 1. User Provides Identity
Just be straightforward it is not the good way , in  fact it is the less secure method , why ? Because we can not simply trust the user , he can enter anything in our system and if there is a human error our system is no longer consistent.
I do not have seen many system do this :wink:
**DO NOT DO THIS**


# 2. Application Provides Identity
This method is the most present now, we let the application generates the Unique Identity with things like UUID , in Java i still use it today . And you can give a more strength unicity by adding a string to that generated UUID . And by looking to that String (UUID + String) we can easily determine the identity of our entity .
it is the method i have seen so much in e-commerce , backend system. From my point of view it is the go to method by far
**IT IS THE METHOD**


# 3.Persistence Mechanism Generates Identity
Here the main idea is to have a persistence system which is going to return a key or a number that our bounded context is going to use to create the UNIQUE IDENTITY of our entity but the drawback is PERFORMANCE, if for create a entity we have to do a request to the persistence system , in small system it works , but if the system grows we face performance issue.
So from my point of view , we can start with it but as the system grow we go with the _Application Provides Identity_


# Another Bounded Context Provides Identity
It Is in the application provides identity but the characteristic here is that , it is not the current bounded context but another one which is responsible to create this unique identity , the main advantage is the _Autonomy_ , because each bounded context has its roles.
But there is so many drawbacks like _Integration_  and _Translation_ (with _context mapping_ the two have to communicate) because we have firstly to integration the two bounded contexts and secondly to translate the data coming from the other Bounded Context to the data for the current bounded context.
Even the book says that this method is quite complex but can be done simple with _Domain Event_ :wink:


:anguished: Oh no so many new words

:grimacing: Keep Calm it is the vocabulary of Domain Driven Design , i will try to write a post about each of them if JESUS permits me.


Thanks for reading , Connect With Me Here
[GitHub](https://github.com/EdgarEmmanuel)
[Twitter](https://twitter.com/home)