Skip to content

Presenters inheritance

Ahmad K. Bawaneh edited this page Nov 7, 2021 · 1 revision

One of the things that we might have noticed that we are using different annotations for different settings on a proxy instead of using a single annotation with more arguments, this is because those settings can be inherited from base proxy classes, Domino-mvp will look for the annotations in the whole class tree, for example you can make a base proxy class and annotate it with @AutoReveal then for all proxy classes that inherits from that class will be AutoReveal even if you don't specify the annotation directly on them, same for all other annotations, except the @PresenterProxy since it is what actually make the class a proxy.

And this is not only for the class level annotations, but also for all annotations that goes into the class methods, so @PostConstruct, @OnInit, @OnBeforeReveal, @OnReveal, @OnRemove, @RevealCondition ...etc. and all annotations that we will study as we go with this documentation works on base classes unless we specify that they don't, this will give you a lot of power when you want to implement common behaviors in your application.

For example, what if I want to register some audits log when ever a user navigated to a view that should be logged, it would be a too much to implement this behavior in every view, so instead we can do something like this :

The base class

@Slot("content")
@AutoReveal
public abstract class AuditLogProxy<V extends View> extends ViewBaseClientPresenter<V> {

    @PathParameter
    String viewName;

    @OnReveal
    public void auditLog(){
        //send audit log to the server
    }
}

Then child classes could be something like this :

@PresenterProxy
@AutoRoute(token = "app/foo/:viewName")
public class ScreenFooProxy extends AuditLogProxy<ScreenFooView> {

}
@PresenterProxy
@AutoRoute(token = "app/bar/:viewName")
public class ScreenBarProxy extends AuditLogProxy<ScreenBarView> {

}

and they will inherit what ever settings from the parent class annotations.