How to have multiple addresses in one class of person?

Asked

Viewed 319 times

6

If a person has more than one address. The code below is correct?

public class Pessoa implements Serializable {
    private static final long serialVersionUID = 1L;

    private int codigo;
    private String descricao;
    private String dataNascimento;
    private String cpfcnpj;
    private PessoaEndereco pessoaEndereco;
  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

1 answer

7

No, this way you can only get one address. There are several ways to allow more than one address, one of them, perhaps the simplest, is this:

public class Pessoa implements Serializable {
    private static final long serialVersionUID = 1L;

    private int codigo;
    private String descricao;
    private String dataNascimento;
    private String cpfcnpj;
    private ArrayList<PessoaEndereco> Enderecos;

I put in the Github for future reference.

Obviously you should have methods of accessing the various addresses easily. The only change was to create an address list where only one.

Browser other questions tagged

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