@Externals are a good way to support MVVM in DecleX, they manage automatically the Binding of the elements, which is common in modern frameworks like the reactive ones... But, there's another architecture which also is good to have support to, and this time, with a feature which could expand even more.
Let's say you are implementing MVP in your app, you also use an @External as a Presenter, to forward all the user inputs directly to it, but now, you need to call specifically methods in the View, the main difference between MVVM and MVP is that you the the Presenter knows about the View (in MVVM it has no knowledge about what the View is).
But one of the problems of MVP is all that link and implementation of interfaces, every single feature you want to implement you need to add entries to some interface which whatever the case, must be added and entries should be maintained, in Java language they are duplication at the very end of your code (or your code duplication of them), since you have to define the interface, and then define all the methods links to them.
That's one of the steps we are willing to get rid of, with the help of DecleX.. also with the code injection capabilities of DecleX, injection should be used for this as well.
Let's put this in an example. The first thing to implement is a system to implement interfaces without requiring to much coding. One good way is automatic reference of interface (and it will be automatically created similar to events), for instance:
@Method(ViewInterface.class)
public void showUserValue(String userValue) {
//Do something here
}
@Method(ViewInterface.class)
public void hideSomeModel() {
//Do something here
}
Or let's say that you will implement in your View only one ViewInterface, it is simple to do:
@Implementing(ViewInterface.class)
public class MainActivity extends Activity {
@Method
public void showUserValue(String userValue) {
//Do something here
}
@Method
public void hideSomeModel() {
//Do something here
}
}
In whatever the case, ViewInterface will be implemented, and it should be fully Injectable from any View, maybe we should allow the creation of @EInterface, an inject them with @InjectInterface.
@External
public class MyPresenter {
@InjectInterface
ViewInterface view;
void someMethod() {
view.showUserValue("some value");
}
}
The view can be used autoamatically, tne the @Bean can be injected only in views "implementing" that interface, so that the injection can proceed automatically
@Implementing(ViewInterface.class)
public class MainActivity extends Activity {
@Bean
MyPresenter presenter;
@Method
public void showUserValue(String userValue) {
//Do something here
}
@Method
public void hideSomeModel() {
//Do something here
}
}
So in this way you can have MVP without the need of lot of Binding, Linking or Interfaces implementations.
Note that this method can be used to implement any pattern in which the @Beans should have an injected reference to its container.
@Externals
are a good way to support MVVM in DecleX, they manage automatically the Binding of the elements, which is common in modern frameworks like the reactive ones... But, there's another architecture which also is good to have support to, and this time, with a feature which could expand even more.Let's say you are implementing MVP in your app, you also use an
@External
as a Presenter, to forward all the user inputs directly to it, but now, you need to call specifically methods in the View, the main difference between MVVM and MVP is that you the the Presenter knows about the View (in MVVM it has no knowledge about what the View is).But one of the problems of MVP is all that link and implementation of interfaces, every single feature you want to implement you need to add entries to some interface which whatever the case, must be added and entries should be maintained, in Java language they are duplication at the very end of your code (or your code duplication of them), since you have to define the interface, and then define all the methods links to them.
That's one of the steps we are willing to get rid of, with the help of DecleX.. also with the code injection capabilities of DecleX, injection should be used for this as well.
Let's put this in an example. The first thing to implement is a system to implement interfaces without requiring to much coding. One good way is automatic reference of interface (and it will be automatically created similar to events), for instance:
Or let's say that you will implement in your View only one ViewInterface, it is simple to do:
In whatever the case, ViewInterface will be implemented, and it should be fully Injectable from any View, maybe we should allow the creation of @EInterface, an inject them with @InjectInterface.
The view can be used autoamatically, tne the @Bean can be injected only in views "implementing" that interface, so that the injection can proceed automatically
So in this way you can have MVP without the need of lot of Binding, Linking or Interfaces implementations.
Note that this method can be used to implement any pattern in which the
@Beans
should have an injected reference to its container.