Let's say I have a table for storing users. In this table, I have data like id, name, address, bank account and birthdate. Also, I have two domains in my codebase; in one of them, I need a user entity with id, bank account and address; in the other domain, I need a user entity but only with name and birthdate. The first domain could be something related to subscriptions (hence the banking info), where the second could be related to permissions for accessing specific content inside the platform (hence the birthdate).
Since I am a beginner with DDD, I'd like to know if, modling-wise, it is correct to have different entities with partial data from a table, where both entites represent the same thing in the real world, but are only partial references to that object inside the domains. Or I should have a shared
folder with the complete entity there?
From my perspective, my first take makes more sence, since I am being specific about the domain and I'd not be overloading my entities and queries from the database too. But anyways, I need or confirmation, or correction.
-
1Where you say "age" I choose to interpret that as "year of birth". (Storing Alice's then-current age when your system was running in 2021, and Bob's current age when he uses the system today, would lead to ambiguities about who is older. If what you really want to model is "this person is old enough to enter into a legally binding contract", then a simple boolean might suffice, backed up by a seldom accessed log entry describing the identity documents we verified.)J_H– J_H11/03/2023 18:40:35Commented Nov 3, 2023 at 18:40
-
@J_H, yes, you're correct. I changed it to make more sense.Bernardo Benini Fantin– Bernardo Benini Fantin11/03/2023 18:44:15Commented Nov 3, 2023 at 18:44
1 Answer 1
Modeling-wise: this is fine. The modelling should come from the domain, not the tables, and the tables are an implementation detail. You might even change the table structure to normalize/denomalize (in the Codd sense) the data.
When it comes to implementation, you may need to do something to cope with the fact that your objects only map to some of the information in a row, when you write or update it. Or you may not. Depending on how your ORM works.
Modeling-wise, you should consider if "partial" data is OK in the business domain. Can there be users whose age you know but not their address? etc.
-
I do think "partial" data is ok from the domain perspective, because the whole idea is "slicing" a user for each domain. Like, a user is a user, a client (for payment), maybe a manager inside the system, and each of those is part of a a user that is only partially seen bu each domain. Just like a man is a father, a dev, a husband, etc, but only the database has all that data, for each aspect of his life, he's one thing per domain (fater, dev, husband).Bernardo Benini Fantin– Bernardo Benini Fantin11/09/2023 16:36:49Commented Nov 9, 2023 at 16:36
Explore related questions
See similar questions with these tags.