I have a heritage hierarchy with overlap, the system knows about people who can be customers, providers and agents. A person should be one of these classes, but can be related to two or three, that is, a person can be a customer and a provider at the same time.
In the database, I think the problem has been solved, one table per square (individual, customer, provider and agent table) and the primary key of the sub-class table is the primary key of the super key table. foreign key. (Any possible improvements will be welcome :))
The problem comes in the Java world, I do not know the best way to map this database design for my Java POJOs. I have three possible disturbances
-
In the subclasses, with a union of all areas, how a person knows, a different area will be required for this problem The person who is not a customer , Ekin is a provider, he will be set to clear all client-related fields.
-
Common area for subclasses and three "DTO-type" properties that hold areas related to each subclass. In this way we have only one or two fields in place of tens.
-
An abstract class for the person and seven subclasses, a possible combination of three subclasses i.e. customer, provider, agent, clientprovider, client agent ... clientprovider agent: s ( Of course, their respective interfaces with each)
This is a webapp
The question is: what is the best way to solve this problem ?
Thank you!
IMO legacy is not the best way to model it, I try to combine instead .
You can easily add new role types and many role classes (a common interface based on context, or a role member of Anum When applied). , And dynamically attach / separate roles from / to a person. (You can be a person without a role, it may be required.)
ANY example:
Interface role {...} Final category Client tool role {. ..} The final category provider applies the role {...} The final category agent applied role {...} class person {list & lt; Role & gt; Roles; Public Zero addRole {...} Public Zero Deletion Role (Role Role) {...} The public role gets Rolof Type (class & lt;; increases role; role type) {...}}
Update: Anem-based example
This is applicable when roll objects do not have a state, thus giving you a single role instance for each person .
role [customer, provider, agent; // potential member, constructor etc}
The individual square is almost the same as above, except that
- I
-
getRoleOfType ()
does not make any sense here, so I have it forhasRole () Has changed with)
.class person {set
Comments
Post a Comment