If you need to model your customers by identifying whether they are a legal or natural person, you could have just two entities:
-
Person , whose identity would be your national registry, a field called for example CpfCnpj
(yes, these documents have the same character, it is natural to use the same field). This entity would have an attribute to identify whether it is a natural or legal person (filled in the database for example with F
or J
). The few exclusive fields of individual or legal entity may not justify two distinct tables.
-
Client , which does not need hierarchical relationship with person but just referencing a person. To identify then whether a customer is an individual or a legal entity, you refer to the Person entity to which he is related.
If in the domain the types of client (physical / legal) really characterize different types of entities, then you would have here two classes: Client Individual and Client Corporate . More:
Please note that a domain where Individuals and Legal Entity are rare are separate entities. Usually we just need to differentiate them through their attributes to make some decisions during the sales process.
And it's also rare for a domain where a Person entity really exists. Usually it only appears in the code to facilitate reuse and design of the database.
Real domains, rather than having a Person entity, actually have Client , Employee / em> ... Some of these entities are the same person in real life but for the system they remain distinct entities because they have different purposes in the domain.
Conclusion
Most problems in modeling people appear during exercises. This modeling seems an interesting problem but in practice it is not. Look at the systems out there: they have a "Person (s)" table and that's it.
Even well-modeled systems generally do not need to distinguish physical and legal persons as separate entities but only as an attribute that characterizes them as being of one type or another; not only because it is simpler to model but because that is the real domain of the problem.
When the domain requires different entities depending on the type of person, generally what it requires are not "people" of different types but rather, "clients" of different types. In these cases (rare), "Person" remains there being the same for both physical and legal and the client is specialized in: Customer Individual and Client Corporate . p>
Suggestion
When modeling, whether by exercise or by professional need, first try to define the problem well in a business language, and then model problem-oriented rather than how you would like to implement it.