android - Model View Presenter - same view, different presenters -
i'm building 1 android app using mvp, , have 1 question pattern.
say have 1 screen creating new person. screen show 1 edittext
inserting name, surname, 1 imageview
show picked photo picture, etc. lead 1 view
interface, implemented fragment
. cooperate 1 presenter
interface, implemented class.
fine.
now have feature: screen editing existing person. happens, view
feature identical 1 creating new person. however, presenter
different. start loading existing person db pre-populate view current data, , action on database when clicking "save" update instead of insertion.
so, think example of mvp where 1 view works different implementations of presenter achieve different use cases.
do think correct assumption, or think different features should have different
view
,presenter
interfaces?also, if you'd common
view
, differentpresenters
, implementation ofview
common, or lead same interface implemented 2 classes? in practice, see 2 options.having 1
fragment
implementingview
. depending on whether user create new person or update existing one, fragment should receive , use different presenter.having 2
fragment
s. each 1 instantiate differentpresenter
. use composition or inheritance avoid replication of code between 2 fragments.
what think better in these cases?
thanks.
you'll run when create crud-like application using mvp pattern on android.
you can have single view, long document in class impl 'view' 2 different presenters, 'is okay'
i suggest creating 2 views, 1 'create' , 1 'edit' (they might same(for now), separating them makes clear -are- different things.)
you see situation in future (or impl of pattern) 'create' , 'edit' views have different apis. or different visual cues, such button labelled 'create/add' in 1 , 'update' in another.
i'd make view-library/helper class both views pull logic from. should reduce overall loc, if make 2 'view' classes. benefit of change either create/edit views without worrying impacting other. (i tend think 2 view files, easier maintain down road when there 'slight' variance between create/edit)
Comments
Post a Comment