निम्नलिखित छद्म कोड है कि एमवीपी पैटर्न को लागू करता है पर विचार करें:एमवीपी डिज़ाइन पैटर्न सबसे अच्छा अभ्यास
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();
}
}
और यहाँ एमवीपी पैटर्न के एक विकल्प के कार्यान्वयन है:
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();
}
}
एक कौन सा एमवीपी की अधिक सही कार्यान्वयन है पैटर्न? क्यूं कर?
कोड समीक्षा इस प्रश्न के लिए एक बेहतर जगह हो सकती है, आपको कुछ अच्छे उत्तर मिलेंगे: http://codereview.stackexchange.com/ –
@Jezzabeanz उसे इसके लिए वास्तविक कोड की आवश्यकता है, हालांकि छद्म कोड नहीं। – Riker
राय के बिना मैं बिना किसी राय के लिए कैसे पूछ सकता हूं? – CarlLee