vendredi 6 décembre 2019

Am I implementing MVP architecture correctly?

Currently I implemented the MVP architecture into one of my Activities. It works, but I need some clarification if I am doing it correctly.

In my Activitiy's contract I have

public interface MainActivityContract {
    interface View{
        void updateEventName(String eventName);
        void updateEventDate(String eventDate);
        void updateEventTime(String eventTime);
    }

    interface Presenter{     
        void setEventName();
        void setEventDate();
        void setEventTime();      
    }
}

And in my MainActivity I would call the method

mPresenter.setEventInfo(mInfo);

from my MainActivityPresenter class:

private EventDto.EventInfo eventInfo;

@Override
    public void setEventInfo(EventDto.EventInfo eventInfo) {
        this.eventInfo = eventInfo;
        setEventName();
        setEventDate();
        setEventTime();     
    }

    @Override
    public void setEventName() {
        view.updateEventName(eventInfo.getE_name());
    }

    @Override
    public void setEventDate() {
        view.updateEventDate(eventInfo.getE_day());
    }

    @Override
    public void setEventTime() {
        view.updateEventTime(eventInfo.getE_time());
    }

Is it correct to call all the update methods when calling one of the mPresenter methods?

mPresenter.setEventInfo(mInfo);

Otherwise I would have to call the update methods one by one

mPresenter.setEventName()
mPresenter.setEventDate()
mPresenter.setEventTime()

Aucun commentaire:

Enregistrer un commentaire