Physical and Juridical Person

Asked

Viewed 490 times

0

I have a field which can receive physical or juridical person, as you model it ? through interface, composition or heritage ?

I have the following class structure: Contacts (PF only) -- belongs to a --> Company (PJ only) Contacts have several roles, such as: Seller, Proprietary, etc

public class Contato {
  private Empresa empresa;
  /* ... */
}

public class Empresa {
  private Set<Contato> contatos;
  /* ... */
}

But I also have the following situation

public class MeuObjeto {
  ??? responsavel;
}

in such cases the person responsible may be a Contact (Physics) or a Enterprise (Juridica). I would not like to fall into the solution of Person -> Physical Person, Person -> Juridical Person, I thought about using an interface, but it may end up growing too. The doubt is someone knows some more pattern that can help in the logical modeling of this situation?

** improving the question

  • 3

    Do you speak in classes, in comic books or in both? I would use inheritance or composition, depending on what else I wanted to keep information, but I don’t have a definitive answer, I think I would analyze case by case...

  • 6

    Look Macedo here we do not give opinions, we do not say what we do, because this will not help you in fact. We give you objective answers that can really help you and other people. Try to modify your answer by putting more details of what you are doing, if you are having any problems, finally try to make the question more objective. Develop further what you are thinking of doing with these shapes you have listed, and you can save the question. But already I put it, each case will be different. So try to show well what your case is.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.