1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MVVMを実装するにあたっての備忘録

Posted at

初めに

今回はMVVMアーキテクチャを採用するにあたって最低限意識したいことを備忘録として記述していきます。

MVVMについて

MVVMとは

Model, ViewModel, View で構成されるアーキテクチャです。
iOSでいうところのViewControllerはここでいうViewに含まれます。

Model

MVCやMVPのModelレイヤーと同じ
APIで取得してきたデータを表現する
(データが更新されたらViewModelに通知する)

View

ViewModelとバインディングする
UI のレイアウトなど表示に係る処理
UI イベントの ViewModel への伝搬
ビジネスロジックは書かない
例えばテキスト入力のバリデーションの処理などは書かない
テキストを ViewModel 経由で Model に渡して Model でバリデーションしてその結果を ViewModel 経由で View に渡して処理するのが正しい

ViewModel

Model と View の橋渡し役で表示に関わる処理 (プレゼンテーションロジック)を書く、ビジネスロジックをここで持たせることもある
Viewからの情報を加工してまたViewに返す(表示更新)
Model のどの要素が UI のどの要素にマッピングされるか
UI のどのイベントが Model のどの操作にマッピングされるか

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?