Our team is working on a refactor where one of My Team mate is refactoring a component "XFormComponent" using MVP
so the XFormComponent now has
- XFormFragment implements XFormComponent.View
- XFormPresentor implements XFormComponent.Presentor
- XFormModel
Now I need to create another MVP - "AllFormsComponent" this component displays all the forms components including "XFormComponent", "YFormComponent" etc as list of fragments.
So I will have
- AllFormsComponentFragment implements AllFormsComponent.View
- AllFormsComponentPresentor implements AllFormsComponent.Presentor
- AllFormsComponentModel
Now my question is , who "AllFormsComponentFragment" or "AllFormsComponentPresentor" will be responsible for creating subMVP comonents i.e XFormFragment ?
My thoughts is
// The V of MVP
public class AllFormsComponentFragment implements AllFormsComponent.Views extends Fragment {
@Inject AllFormsComponent.Presentor myPresentor = inject();
private AllFormComponentModel mAllFormComponentModel;
public static AllFormsComponentFragment newFragmennt(AllFormComponentModel allFormComponentModel) {
// make fragment with model
}
List<FormModel> models = myPresentor.getListofFormModels(mAllFormComponentModel);
for(FormModel model : models ) {
// create the FormCompoent (Views) Fragments, and give to fragment manager.These individual component will create their own presentor
}
}
// The P of MVP
class AllFormsComponentPresentor implements AllFormsComponent.Presentor {
@Override
public List<FormModel> getListofFormModels(AllFormComponentModel model) {
// return the list of models
}
}
public interface AllFormsComponent {
interface View {
// view related methods
}
interface Presentor {
// gets the list of models for the component MVP's
List<FormModel> getListofFormModels(AllFormComponentModel model);
}
}
My questions are ,
-Does this approach sound valid . I am new to using MVP, so feedback and suggestions are welcome.
-I am still a bit confused about communication. e.g : if AllFormComponentModel Model changes, all components Fragments need to get the updates - how should this communication be created . a PubSub archi ? or AllFormComponentFragment just sends the updates downstream. How about rotation handling. the child fragments would be creates before the parent fragment when rotated, how are these handles in MVP communication.
- These nested fragments make me think , do the component fragments - need to be fragment or can that we avoided gracefully ?
Aucun commentaire:
Enregistrer un commentaire