It was recommended, in this question, to maintain the relationship between Physical Person and Employee as generalization (Employee extends Physical Person). I do not understand why it is not in this case to make a paper relationship (Employee is role of Person), at least as I understand that roles work.
It was recommended in the question, not in the answer. I find a mistake and said that Funcionario
is a role of PessoaFisica
. Because if that person is also a client and is a specialization, therefore inheritance, the only solution is to have two instances of the same person, which is a conceptual madness, or to save space in the person to be everything that it can be.
Taking this second case has two ways of doing: one is to keep everything together and the other is to have external references.
Keeping together in memory only gives with huge waste, and in DB, or has this problem too, or needs a format without scheme, which can bring other problems.
Keeping it separate in memory is not too complicated, in a database is exactly what the role model does. It’s much more obvious to do so, so it’s not really a legacy, also because it’s something dynamic that the programmer has no control over.
The solution that people make is to have more than one person among the data representing the real person. It’s an obvious gross mistake that "nobody" sees.
Can’t you ever do it? It can, like optimization or if it really makes sense. Forbidden is never.
As access optimization you can keep in the papers all the data from Pessoa
not to have to look more than one table, but to have a writing cost (which can be advantageous) since any data change in the Pessoa
has to obligatorily and preferably atomically update all the roles that that person will have.
A detail of implementation of papers is that it is usually more interesting to have a mechanism that indicates what roles that person actively possesses. This can be a few columns (then only with programmatic change to add some new, and may have some waste of space), it can be schemaless with a "array" of papers (not all Dbs allow easily), or may have an extra table that does the mooring (very expensive cost of access). In memory is not much different, except that it has more difficulty to be without schema without an auxiliary table, but in compensation an extra table costs cheap in this device.
Paper is just a simple composition, just as you can have N sales of a product, you will have N roles of a person. In fact the normal will be quite low N, in most cases should be 1. Is to think what makes more.
A justification may be that from there it is strange the entity Vendendor
be "role of a role", that is, Seller be role of the Employee, which in turn is role of Individual. But I would like a further clarification.
Exactly, a role being attached to a role does not make sense, who has the role of Vendedor
? To Pessoa
. In this case it can be physical or legal (even if your model never accepts this who guarantees that in the future will not accept?), has already broken the model of Vendedor
be bound by Funcionario
. But if someone says it’s different, okay, every real situation can ask for something different.
In the comments has a model of roles I don’t like it, I don’t know if that’s what I call paper. But it might just be that I’m confused about what I already know. Anyway it has very bad examples, full of seemingly unnecessary things.
I see no harm in physical person playing a role
I didn’t either.
What I said was that a PessoaFisica
should not be a role of Pessoa
. But I made the caveat that this vision is valid in some scenario.
Concretely you, or have a PessoaFisica
, or has a PessoaJuridica
. Pessoa
is naturally an abstract concept, which can give the impression of not being because we tend to believe that person is a human being. We are talking about personality according to legislation. There is not only Pessoa
, from the legal point of view does not have this object, no one is just that, there are no descriptions for what would be this object. For physical or legal has: lists the necessary documents, a name, address, sex or activity, has date of birth/foundation, etc.
One cannot play a role in something that even exists. One must have a concrete concept based on something that can be generalized. In fact in relational databases it is normal that Pessoa
evaporate when shaping the physical. At most you will have a view that allows access PessoaFisica
or PessoaJuridica
without distinction.
But it’s said there that it’s not the end of the world Pessoa
concrete, just find inefficient for little or no benefit, you would always have to access two tables to get everything you need in most cases. This is a case that does not risk having the same entity being represented by two objects in the roll manipulated data. Papers are not only good, they are necessary to not turn mess. The simple should always be preferable and in this case the simple is to have no paper. Who wants to complicate that should justify what problem he wants to solve with complication.
I know how to justify the use of roles among concrete people. That’s partly what’s up there.
I tend not to use 1:1 relations in the model (not to confuse 1:1 in the data), I find them unnecessary in most cases, and where it is usually is to solve another problem created mistakenly. Again, if you think you should wear something like this, you have to justify.
Have you seen the question What is the advantage of a 1:1 relationship?? There it speaks of 1:1 data and not model, and if we analyze well, except for the first, all the others are for need of mechanisms, it has nothing to do with the conceptual model. I speak which is the ideal model, if the mechanism requires something else is part of another scope.
I only care about it because I know the difficulty that it is to change something when it has been misconceived (and we always do this, there is no way to do perfect always), and I like to do it optimized. If you can let go of one of those things it matters less, if you can let go of both, then everything goes.
As Bacco said in the comments, modeling has to be based on facts. The problem is that many models are made in assumptions, and visions of reality that are not real. And it’s easy to fall into that trap. I keep falling in domains I haven’t worked yet, and even the ones I’ve worked on make some mistakes.
Usually for me the Employee is a specialization (maybe what you call paper) of Individual. Just as Client is another specialization, System User is more a specialization, and so it goes. After all, they are people, right? And all people potentially could be any or all of the aforementioned specializations. I don’t even see confusion in it, for me modeling is merely a formal description of reality.
– Bacco
On the question of the excludent, I see two more obvious ways. Either you have juridical and physical, without mixing, or you have "entities" and the juridical person and physical person are specializations (which does not rule out that physics continue to be treated as I mentioned at the beginning). I tend not to mix the 2 things (which does not mean not reuse the relationships in common points, are things that can be administered without problem), but there is case by case.
– Bacco
I do not call role of specialization but rather a relationship Individual "has role" or "performs role of" Employee. Example Company having Buyer, Seller papers, etc. (taken from here). It’s a relationship of composition.
– Piovezan
These examples I find quite nonsense, because they invent unnecessary figures (or have bad names for things). I don’t know if the problem is nomenclature, but I think it’s too extensive for comment. Unfortunately there is a lot of large and famous company that follows this line of examples.
– Bacco
Has in the Wikipedia also (Figure 3).
– Piovezan
The one on wikipedia is much better, use "person". Except for a "bot", a seller is really a person, a buyer too (it can be legal, then it comes down to what I say about convenience for your case), and a employee is also a person. And this person can be all at once. More than modeling, it’s fact. "Company role" for me does not carry any sense. " Person" I know what it is without need of explanation.
– Bacco
I agree with everything Bacco has said so far, later I can see better.
– Maniero
Do you think it’s strange the Company? I should have shown this figure, the other only makes a generalization about the roles. For me it is the same relationship that in Person, "has role", "can act as one". Relationship of composition. Does not see sense in the case of Company also?
– Piovezan
I can’t see a company relating to a vendor or a Costomer. I can see a company relating to a person with a vendor role and/or Ustomer. This last figure is jumping the person.
– Bacco
Sorry, I think I contextualized wrong for you. In the example of Company is the company itself that is assuming the role of Vendor or Customer. She (the company) is a Seller or Buyer of products.
– Piovezan
Ah, but then we’re out of your question. You can even have a direct sale online etc, but the subject begins to get broad if we cover all possibilities.
– Bacco
All right, I’m just using the example that the article gave. I learned from it. We can stay in Person then. In Person you see sense. Does it make sense that the Employee is the role of Individual? I’ll reread what you wrote.
– Piovezan
Right. I wouldn’t have much to add, I just think you really have to take your real problem and solve, as long as you describe the situation well. There’s no magic recipe for every case, just principles, I guess. Mine are to make things as simple as possible and to make things self-describing (That’s why you won’t see me in the posts with too much academicism, I find life too short for this :D - I think if I had good recipe that served for everything, would have consolidated, and if not, we will solve in the real case that is faster)
– Bacco
I don’t see how academicism the application of roles, I’m just wondering if they apply to that particular case. As in general heritage It greatly enhances relationships, I thought that composition in this case would make the design more flexible (if such a relationship fits conceptually).
– Piovezan
"And all persons potentially could be any or all of the specializations mentioned" (there in the first comment) did not understand, you are talking about multiple inheritance?
– Piovezan
@Bacco Or a hierarchy with some levels?
– Piovezan
Hi, I think it’s what has in the @Maniero’s answer even, between heritage and composition I would say composition, but I already mentioned that I try not to stick to academicity for that very reason. The theoretical world is "very cool", but at the moment what will command is what the language actually has and what gives of appeal, so I run away from these definitions whenever I can :)
– Bacco
Those who voted against could justify?
– Piovezan