【发布时间】:2016-05-21 08:49:28
【问题描述】:
考虑以下实现 MVP 模式的伪代码:
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();
}
}
这是 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();
}
}
哪一个是MVP模式更正确的实现?为什么?
【问题讨论】:
-
Code Review 可能是这个问题的一个更好的地方,你会在那里得到一些很好的答案:codereview.stackexchange.com
-
@Jezzabeanz 他需要真正的代码,而不是伪代码。
-
不征求意见怎么能征求意见?
标签: java c# oop design-patterns mvp