Try   HackMD

從MVC到MVVM,再到MVVMC的開發經驗分享 - 黃惠勤

所有議程請見議程表

歡迎來到 https://hackmd.io/@iPlayground/2019 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。

請從這裡開始

YouTube

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Slide

MVC MVVM MVVMC from Ng Hui Qin

前言

我沒有要說很多MVC的壞話

MVC其實是很多巨頭APP的根基

簡介

常犯的問題
MVVC解決什麼問題
要注意的問題

MVC 常見的問題

controller 責任太多

如何減少ViewController的負擔(作代碼分類)

  • 有些職責讓Model去做
  • 模組化
  • 避免singleton
  • Extension(Category)

程式的品質 Code Quality

  • unit test (performance那麼高? 請給我加薪!?)
  • 但是MVC寫測試會遇到瓶頸
  • 補充:ViewController的職責太多難以去寫測試

將程式轉移到ViewModel

  • Test Case單純針對ViewModel測試
  • 就有理由不去寫ViewController的測試(?)

畫面複雜時:ViewModel很肥

  • 整理多個ViewModel涵蓋子畫面模組

ViewModel優化

  • 釐清責任
  • Inputs/Outputs Protocol
    • Binding的時候好讀
    • 寫Unit Test也簡單

MVVMC (C - Coordinator)

Sample code:
https://github.com/nghuiqin/Todo-RxSwift-MVVMC

Singleton的隱患

  • 不知道誰改了他的值
  • 想像一下Global Variabal的可怕性
  • 寫測試的時候,他的狀態要怎麼控制 (難)

Dependency Injection

DateFormatter很貴

MVVMC再進化 -> 實戰心得 -> 要注意的坑

  • 不建議使用Xib/Storyboard
  • Coordinator要注意回收的問題,原生回到上一頁時,要特別處理

AppDependency傳入的方法

  • 由於Coordinator有層層關係:
    App -> B -> C -> D
  • 如果只有D需要,B/C也要的帶要怎麼解決
    -> 請大家給建議?勿用萬惡singleton?(myAppManager)

結語

  • 沒接觸過MVVM,可從先從MVVM開始
  • 一人團隊如果沒有太多時間,MVC也不錯

共筆心得

tags:iPlayground2019