Copy of Maniero's response, only in pseudo-Java, to better visualize (and take boilerplate .
Very simplified:
public class Pessoa {
private String nome;
}
public interface Papel {
void umMetodo();
}
public class Cliente implements Papel {
private Pessoa pessoa;
private BigDecimal credito;
}
public class Faturamento {
public void venda(Cliente cliente) {
System.out.println(cliente.getPessoa().getNome());
}
}
If you want someone to be aware of the roles he or she can play in two ways:
public class Pessoa {
private String nome;
private Cliente cliente;
private Fornecedor fornecedor;
}
Each role you add needs to change the class, which violates some principles, but that is not always a problem.
Another way:
public enum TipoPapel { Cliente, Fornecedor }
public class Pessoa {
private String Nome;
private Map<TipoPapel, Papel> papeis = new HashMap<>();
public void adicionaPapel(TipoPapel tipo, Papel papel) {
papeis.put(tipo, papel);
}
}
Instead of enum could use String that can make it easier or difficult, depending on the case. He could use another structure, even more specialized, instead of the map. You could have control of the roles in a separate type that abstracted the map.