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 😃
Firstly when i cam into this , i thought that it was an entity like in java programming language 😳 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.
😩 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 ? 👀
Yes there are three mains methods for the generation of Unique Identity
- User Provides Identity
- Application Generates Identity
- Persistence Mechanism Generates 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 😉
DO NOT DO THIS
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
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
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 😉
😧 Oh no so many new words
😬 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.