mercredi 13 avril 2016

Can I reset Model on the fly in MVP-pattern?

I've got the following presenter:

public interface MyPresenter {
    public void reset(Model m);
    //Some other methods
}

public class MyPresenterImpl implements MyPresenter{
    private final MyView mv;
    private volatile Model m; //Some data container with a little bit 
                              //more complicated structure than Collection<T>

    @Override
    public void reset(Model m){
        this.m = m;
    }

    //Other staff
}

The reason I want to do that is to keep Model implementation immutable and as a consequnce ensure thread-safety. Is it allowable to set a new Model reference when some event occured from MVP's standpoint?

Aucun commentaire:

Enregistrer un commentaire