Y
Y
Ytsu Ytsuevich2015-01-18 13:06:06
Design patterns
Ytsu Ytsuevich, 2015-01-18 13:06:06

Is the MVP pattern only used in .NET?

As I understand MVP is based on events.
View , through its methods on control events ( button1_Click ) raises IView events .
The Presenter has a subscription to IView events . (correct if I'm wrong)
But in some languages ​​there are no events as such (event) (in Java, it seems not). How to apply this pattern without events?
In my opinion, this is impossible ...
PS We'll have to use MVC

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Yeletsky, 2015-01-18
@Tiendil

You have misunderstood what patterns are.
A pattern is not a specific implementation of something, but an approach to organization. What is described in the books is a kind of generalization of the experience of developers. On each PL, patterns can be implemented in different ways. Moreover, since the pattern itself is a generalization of experience, then even in one PL it can be implemented in different ways, depending on the context in which it is used and the specific programmer.
Accordingly, any pattern can be used on any Turing complete PL.
By the way, Events is also a pattern, it's just that in some PLs it is implemented at the language level, in others it is implemented manually. Where they do not exist, you can implement them yourself or use one of the ready-made libraries.

M
mamkaololosha, 2015-01-18
@mamkaololosha

A pattern is a spherical advice in a vacuum on how to solve a particular design problem. It usually boils down to "Here we have something that looks like *pattern name*".

H
halogen, 2015-03-16
@halogen

Quite possible. Used, for example, in Swing (Java) or GWT (Java). Events do not have to be built into the language and be first-class citizen in it. For example, in GWT, an event handler is described as follows:

public interface ILoginView {
    String getUsername();
    String getPassword();
}

public interface ILoginPresenter() {
   void onLogin();
}

public final class LoginView extends Composite implements ILoginView {
// ...
    @UiField TextBox username;
    @UiField PasswordTextBox password;
    private final ILoginPresenter loginPresenter = ...;
// ...
    @Override public String getUsername() { return username.getText(); }
    @Override public String getPassword() { return password.getText(); }
    @UiHandler("login") public void onLoginClick(ClickEvent e) { presenter.onLogin(); }
// ...
}

The annotation @UiHandleris processed by the framework. You can, of course, get by with a less declarative approach and register handlers manually through some kind of addXXXListener(), as is done in Swing.
A view without events can also exist when no feedback is required from the user: for example, a regular one ISummaryViewthat simply displays a few lines of text.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question