model view presenter

21
Model View Presenter Indonesia Dubai, February 2016 Rendra Toro

Upload: rendra-toro

Post on 16-Apr-2017

509 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Model View Presenter

Model View Presenter

Indonesia

Dubai, February 2016

Rendra Toro

Page 2: Model View Presenter

2

why MVP

Page 3: Model View Presenter

3

● Timeline very long for one task or feature on development

to release/live

● Need to change from Manual Test to Automated Testing

● It took a lot of time try to code Automated Testing

● New method Test Driven Development

Things we faced before using MVP

Page 4: Model View Presenter

4

Model–view–presenter (MVP) is a derivation of the model–view–controller (MVC) architectural pattern, and is used mostly for building user interfaces.

Page 5: Model View Presenter

5

MVP Diagram

VIEW

PRESENTER

MODEL

User Event Updates Views

Updates Model State-Change Events

Page 6: Model View Presenter

6

iOS implementation

Page 7: Model View Presenter

7

• View: displays what it is told to by the Presenter and relays user input back to

the Presenter.

• Interactor: contains the business logic as specified by a use case.

• Presenter: contains view logic for preparing content for display (as received

from the Interactor) and for reacting to user inputs (by requesting new data

from the Interactor).

• Entity: contains basic model objects used by the Interactor.

• Routing: contains navigation logic for describing which screens are shown in

which order.

VIPER mean :

Page 8: Model View Presenter

8

How they Connected

Page 9: Model View Presenter

9

Android Implementation

Page 10: Model View Presenter

10

Models, Net, DataStoreFactory, Repositories, Model Mapper

Interfaces

Business Rules (App Workflow, Validation)

Interfaces

View View View View View View

Detail Ad PageHome Page Search Page Chat PageMyaccount Page Other Pages

VIEW

PRESENTER

MODEL

Page 11: Model View Presenter

11

● Platform Specific View (Android: Fragment, Adapter,

Activity, iOS: UIViewController, Storyboard, UITableView)

● Passive, limit action to model and presenter

View

Page 12: Model View Presenter

12

View Diagrams

View Interface

Android/iOS Impl

Presenter

presenter.getListing() view.showLoading() view.showRequestError() view.generateData()

2

1

3

Presenter Interface

view.showLoading()view.showRequestError()view.generateData()

presenter.getListing()

Page 13: Model View Presenter

13

Presenter

● Business Rules happened here.

● Pure Java/Obj-C module without any android/iOS

dependencies.

● Connection to, and from Presenter are done via interfaces

/ abstract class.

Page 14: Model View Presenter

14

Presenter Diagrams

Model

View Interface

Presenter

Validation

Workflow

Interactors

Background Thread

onSuccess(Entity entity)

onFailed(Exception e)

RepositoriesInterface

Android/iOS Impl

2

3

4Presenter Interface

1

Other Java/Obj-c View Impl

presenter.getListing()

view.showLoading()view.showRequestError()view.generateData()

Page 15: Model View Presenter

15

Model

● All data needed for the application are provided here via

Repository Implementation.

● DataStoreFactory responsible for loading data via cache

or API depends on the situation.

● Data origin is encapsulated from the client.

Page 16: Model View Presenter

Model Diagrams

OlxService

CommunicationImpl

CommunicationInterface

APIDataSource StorageDataSource

Repositories

Storage

DataSource Interface

DataStoreFactory

PresenterRepositories

Interface1

2

3

Page 17: Model View Presenter

17

Benefits● Each class has single responsibility,

● Each layer can be tested,

● Abstraction,

● Scalable,

● Easy to maintain.

Page 18: Model View Presenter

18

Road to Test Driven Development● MVP

● Dependency Injection (Dagger 2)

● Unit Testing

Page 19: Model View Presenter

19

Android Libraries

● Retrofit

● Butter Knife (View Injection)

● Dagger 2 (Dependency Injection)

Android Unit Test Libraries

● View - Espresso

● Presenter - JUnit, Mockito

● Model - Robolectric, JUnit, Mockito

Page 21: Model View Presenter

Q & A