1
0

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 5 years have passed since last update.

MVCモデルについて

1
Last updated at Posted at 2021-04-17

はじめに

この記事では、MVCモデルについて簡単にまとめました。
⚠️当方初学のため認識違いがある可能性大です
誤りを見つけた際はコメントにて指摘していただけると幸いです🙇‍♀️🙇‍♂️

参考

この記事は、以下の情報を参考にして執筆しました。

MVCモデルとは

MVCモデルとは、役割ごとにModel, View, Controllerに分割してコーディングを行うモデル、アーキテクチャの一種。
とても多く利用されている。
iOSアプリで利用されるMVCは厳密にはCocoa MVCと呼ぶ。
Controller.png
(https://developer.apple.com/library/archive/documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html から引用)
Model : ソフトウェアを処理
View : 表示
Controller : 入力伝達
User action (View → Controller) : ユーザー操作
Update(Controller → View) : 画面の切り替え(更新)
Notify(Model → Controller) : 通知
Update(Controller → Model) : 情報取得の依頼

Model

固有のデータをカプセル化し、そのデータを操作および処理するロジックと計算を定義。
<例>
固有のデータ → キャラクター(レベル50 攻撃力500) 操作 → 歩く、攻撃 処理 → レベル+1↑ 攻撃力+10↑

View

ユーザーが見る/操作する画面を表示。
ユーザー操作を受け、Controllerを介しModelから操作に対するアクションを受け、画面を更新。
<例>
ユーザーが見る/操作する画面 → カウントアップボタン(1)) ユーザー操作 → ボタンをタップ 画面更新 → カウントアップ(2)

Controller

ModelとViewの仲介役。
Viewのリクエストを受け必要な情報をModelに要求。
Modelから情報を受け取りViewへ渡す。
その他アプリのセットアップ等を管理。
<例>
Viewのリクエスト → 姉から唐揚げ食べたいと言われる Modelへ要求 → 母に姉がからあげ食べたいと伝える Modelから情報を受け取り → 母から唐揚げを受け取る Viewへ渡す → 姉へ唐揚げを渡す

1
0
3

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?