0
I am using the MVP standard in my Android project.
In my mainactivity I have the following components:
private Paciente paciente;
private EditText nome, cpf, cpfTutor, telefone;
private CheckBox checkbox;
soon after I have this method that is started when clicking on a button:
private void initPaciente() {
paciente = new Paciente();
paciente.setNome(nome.getText().toString());
paciente.setCpfTitular(cpf.getText().toString());
paciente.setCpfTutor(cpfTutor.getText().toString());
paciente.setTelefone(telefone.getText().toString());
paciente.setDataCadastro("27/01/2017");
paciente.setStatus(status.getSelectedItem().toString().toLowerCase());
paciente.setTimestamp(new Timestamp(System.currentTimeMillis()).getTime());
paciente.save;
}
Well, if I mean well the concept of MVP this type of direct access to the patient object is not valid.
How do I access these components EditText nome, cpf, cpfTutor, telefone;
by the Presenter?
I tried to access it like this:
private PacienteActivity activity = (PacienteActivity) getContext();
Paciente paciente = new Paciente();
paciente.setNome(activity.nome.getText().toString());
// ...
But that way I have to leave the attributes as public (which I don’t think is cool), or create a lot of geters that will pollute my code.
i studied on Thiengo’s blog: http://www.thiengo.com.br/mvp-android, and has a video on YT: https://www.youtube.com/watch?v=WRGqmqZwEcQ, also on it, which explains better how to use these concepts.
– Carlos Bridi
If you’re concerned about following patterns and "good practices," review the fact that Patient is responsible for recording himself.
– ramaral
Yes, in the above example I had before following the standards. Today the object is responsible for only controlling your data, who persists now is the Model. But anyway, thank you for the tip.
– Rafael Silva