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モデルを理解する

Last updated at Posted at 2020-09-19

Model-View-Controller(MVC)から派生したパターンで、
Presentation Modelパターンを祖先とするデザインパターンです。
ドメイン・ロジックとプレゼンテーション・ロジックを分離する点ではMVCと同じです。

「Model」「ViewModel」「View」の3つの役割から構成されています。
「ViewModel」「View」を併せた部分がMVCモデルの「View」に相当すると認識しています

Model(モデル)

ビジネスロジック部分です。
Modelの役割は、ViewとViewModelの役割以外の部分です。
描画部分とは切り離されていて、ViewModel(ビューモデル)に渡す
または、ViewModel(ビューモデル)から渡されたデータを処理する部分です。

ViewModel(ビューモデル)

ModelとViewの橋渡しを行う点については、MVCモデルのControllerと同じです。
ControllerはViewの表示に関する制御をしませんが、
ViewModel(ビューモデル)はデータバインディング等の仕組みを利用して、
View(ビュー)の表示を制御する部分です。

View(ビュー)

ViewModelが保持するデータをデータバインディング等の仕組みを利用して、
ユーザーに表示する見た目の部分を担います。
または、ユーザーからの入力を受けつける部分です。

MVVMモデルのメリット

・MVCと同じく、役割を分割することで、どの部分に何を書けば良いかわかりやすいです。
・MVCと同じく、ソースに修正が入る際に影響範囲を狭く抑えることができます。
・データバインディング等の機能を利用するため、
 MVCよりも見た目のデザインに専念できる人が生まれます。

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?