Si consideri il seguente pseudo codice che implementa il pattern MVP:MVP disegno del modello best practice
interface Presenter {
void onSendClicked();
}
interface View {
String getInput();
void showProgress();
void hideProgress();
}
class PresenterImpl implements Presenter {
// ...ignore other implementations
void onSendClicked() {
String input = view.getInput();
view.showProgress();
repository.store(input);
view.hideProgress();
}
}
class ViewImpl implements View {
// ...ignore other implementations
void onButtonClicked() {
presenter.onSendClicked();
}
String getInput() {
return textBox.getInput();
}
void showProgress() {
progressBar.show();
}
void hideProgress() {
progressBar.hide();
}
}
Ed ecco un'implementazione alternativa di modello MVP:
interface Presenter {
void saveInput(String input);
}
interface View {
void showProgress();
void hideProgress();
}
class PresenterImpl implements Presenter {
// ...ignore other implementations
void saveInput(String input) {
view.showProgress();
repository.store(input);
view.hideProgress();
}
}
class ViewImpl implements View {
// ...ignore other implementations
void onButtonClicked() {
String input = textBox.getInput();
presenter.saveInput(intput);
}
void showProgress() {
progressBar.show();
}
void hideProgress() {
progressBar.hide();
}
}
che uno è più corretta attuazione del MVP modello? Perché?
Codice recensione potrebbe essere un posto migliore per questa domanda, si otterranno alcune buone risposte lì: http://codereview.stackexchange.com/ –
@Jezzabeanz ha bisogno di codice reale per questo però, non pseudocodice. – Riker
Come potrei chiedere un parere senza chiedere un parere? – CarlLee