How to have multiple addresses in a person class?

5

If a person has more than one address. Is the code below 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;
    
asked by anonymous 06.08.2015 / 04:46

1 answer

6

No, this way you will only be able to have an 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;

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

    
06.08.2015 / 04:48