SlideShare a Scribd company logo
MVP In Practice
MVP, OOP and Unit test
About me
Android developer 2 years+
Name: 洪彥彬
Gitbook:
https://www.gitbook.com/book/hungyanbin/android-un
it-test/
Github: https://github.com/hungyanbin
Forward
Survey
1. 沒聽過MVP
2. 有聽過MVP
3. 有寫過MVP,但是沒在實際專案用過
4. 有在實際專案部分實行MVP
5. 有在實際專案部分實行MVP,並撰寫單元測試
TA
1. 沒聽過MVP
2. 有聽過MVP
3. 有寫過MVP,但是沒在實際專案用過
4. 有在實際專案部分實行MVP
5. 有在實際專案部分實行MVP,並撰寫單元測試
Won’t mention...
1. Concept of MVP
2. Difference between MVP, MVVM and MVC
I hope you know...
1. Unit Test
2. MVP
3. Object-oriented programming
Step 1
Define Contract
Contract
1. 在實作前就先要定義好 → DIP
2. 定義 View 跟 Presenter 職責
3. Contract 應該要看不到 Android framework 的元件(Bundle, Context)
4. 有關 Android Framework UI 元件,都在 View 實作中解決
5. 有關 Android Framework 非 UI 元件,都在 Model 實作中解決
Sample : Login Page
Spec :
1. 可以輸入帳號
2. 可以輸入密碼
3. 點擊登入按鈕後,如果帳密正確,顯示登入成功
4. 點擊登入按鈕後,如果帳密錯誤,顯示登入失敗
Mvp in practice
Step 2
Implementation
Mvp in practice
Mvp in practice
Step 3
Unit test
Mvp in practice
Too easy?
Let’s make it
harder
Show error message
Mvp in practice
Mvp in practice
Any Problem?
Possible Solution:
Before release...
新需求:使用者登入失敗時告訴他輸入了什麼帳號
Mvp in practice
Bad smell
1. 透露實作細節
2. 違反DIP(Dependency Inversion Principle)
3. 依然沒有與 Android Framework(StringRes) 分開,而且使用integer來代表字串
不太合理
4. 滿滿的技術債
讓我們重新思考一下
Mvp in practice
Create a proxy
context.getString()
resourceService.getString()
Mvp in practice
Git diff
What’s the difference??
1. 將context 的職責分出來,職責更清楚了
2. 可讀性比較高
3. Presenter 與 Android Framework 完全沒關係了
ResourceServiceImp(1)
ApplicationImp(2)
Unit test(3)
Summary
可能會遇到的實務困難
1. Presenter 與 Model 的職責不好決定
2. Presenter : View 是一對一?多對一?多對多?
3. 與 Android Framework 切不乾淨
4. 不會寫單元測試
一點點小心得
1. 要不要“全部”用MVP自己決定
2. 使用單元測試會知道自己設計的缺陷

More Related Content

PPTX
持續整合與單元測試
PPTX
打造完全免費的,JAVA專案持續整合環境_ 2013 java developer_day_by 李書豪
PDF
軟體品質與持續整合
PDF
測試是什麼
PPTX
A dev ops team's practice in trend micro in agile summit 2018
PDF
Component Unit Test
PDF
Why use dependency injection
PDF
TDD (Test-driven development, 測試驅動開發) 基本教學
持續整合與單元測試
打造完全免費的,JAVA專案持續整合環境_ 2013 java developer_day_by 李書豪
軟體品質與持續整合
測試是什麼
A dev ops team's practice in trend micro in agile summit 2018
Component Unit Test
Why use dependency injection
TDD (Test-driven development, 測試驅動開發) 基本教學

Viewers also liked (20)

PPTX
Android動態ui介面設計
PDF
React native sharing
PDF
Green dao 3.0
PPTX
Android Effective UI: Tips, Tricks and Patterns
PDF
Android Architecture MVP Pattern
PDF
What is FED
PDF
Trend Micro Web's Scaffolding tool
PPTX
GreenDao Introduction
PDF
Green dao
PDF
Skroutz Android MVP and Adapter Delegates presentation
PDF
React native redux_sharing
PDF
Infinum Android Talks #12 - MVP design pattern for Android Apps
PDF
React Native for Web
PDF
React Native Firebase Realtime Database + Authentication
PDF
RxJava 2.0 介紹
PDF
React-Native Lecture 11: In App Storage
PDF
Rxjava 介紹與 Android 中的 RxJava
PDF
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
PDF
React Native: Developing an app similar to Uber in JavaScript
PDF
React Native Firebase
Android動態ui介面設計
React native sharing
Green dao 3.0
Android Effective UI: Tips, Tricks and Patterns
Android Architecture MVP Pattern
What is FED
Trend Micro Web's Scaffolding tool
GreenDao Introduction
Green dao
Skroutz Android MVP and Adapter Delegates presentation
React native redux_sharing
Infinum Android Talks #12 - MVP design pattern for Android Apps
React Native for Web
React Native Firebase Realtime Database + Authentication
RxJava 2.0 介紹
React-Native Lecture 11: In App Storage
Rxjava 介紹與 Android 中的 RxJava
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
React Native: Developing an app similar to Uber in JavaScript
React Native Firebase
Ad

Similar to Mvp in practice (20)

PDF
React-Native share
PDF
CICD Workshop 20180922
PPTX
2012/05/23 AU Talk - 讓事情發生
PPTX
极速 Angular 开发:效能调校技巧 (ngChina 2019)
PDF
初探GitHub Copilot - 2025 Global AI Bootcamp
PDF
透過測試提升軟體品質 - twMVC#7
PDF
twMVC#07 | 透過測試提升軟體品質
PDF
如何與全世界分享你的 Library
PDF
評估驅動開發 Eval-Driven Development (EDD): 生成式 AI 軟體不確定性的解決方法
PPT
20111130 g24分享(i phone ux)_leona(public)
PDF
银弹!银弹! 徐毅@Italk salon 2011
PDF
DevOps Days Taipei 2018
PDF
Csharp基礎程式設計課程...........................
PDF
過來人經驗 - 在企業中推行 DevOps 前該具備的認知與工具箱
PPTX
除錯、測試與效能
PDF
12. 除錯、測試與效能
PPT
PHP 单元测试
PPTX
[VideOhya] Titanium開發經驗分享_1020
PPTX
Scrum过程介绍
 
PDF
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
React-Native share
CICD Workshop 20180922
2012/05/23 AU Talk - 讓事情發生
极速 Angular 开发:效能调校技巧 (ngChina 2019)
初探GitHub Copilot - 2025 Global AI Bootcamp
透過測試提升軟體品質 - twMVC#7
twMVC#07 | 透過測試提升軟體品質
如何與全世界分享你的 Library
評估驅動開發 Eval-Driven Development (EDD): 生成式 AI 軟體不確定性的解決方法
20111130 g24分享(i phone ux)_leona(public)
银弹!银弹! 徐毅@Italk salon 2011
DevOps Days Taipei 2018
Csharp基礎程式設計課程...........................
過來人經驗 - 在企業中推行 DevOps 前該具備的認知與工具箱
除錯、測試與效能
12. 除錯、測試與效能
PHP 单元测试
[VideOhya] Titanium開發經驗分享_1020
Scrum过程介绍
 
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
Ad

More from 彥彬 洪 (11)

PDF
Rx java testing patterns
PDF
Rxjava2 custom operator
PDF
PDF
Android material theming
PDF
Kotlin in practice
PDF
Jsr310
PDF
ThreeTen
PDF
科特林λ學
PDF
Android 6.0 permission change
PDF
設定android 測試環境
PDF
Green dao
Rx java testing patterns
Rxjava2 custom operator
Android material theming
Kotlin in practice
Jsr310
ThreeTen
科特林λ學
Android 6.0 permission change
設定android 測試環境
Green dao

Mvp in practice