0
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?

【Software】MVVM と Clean Architecture の違いと関係

Posted at

はじめに

Android や iOS、Web 開発において、MVVMClean Architecture という言葉をよく耳にします。
一見すると似たような「設計の話」に聞こえますが、実際には適用範囲や目的が大きく異なります。
本記事では両者の違いと関係性を整理します。


MVVM とは?

MVVM(Model-View-ViewModel) は、UI 層を中心にした アーキテクチャパターン です。

目的

  • UI とビジネスロジックを分離する
  • 状態管理を ViewModel に集約し、テストしやすくする
  • データバインディングやイベントを使って、View と ViewModel を疎結合にする

構成

  • Model:データやドメインロジック
  • View:画面や UI コンポーネント
  • ViewModel:UI 状態やイベント処理を保持する仲介者

Clean Architecture とは?

Clean Architecture は、Robert C. Martin(Uncle Bob)が提唱した アーキテクチャスタイル です。

目的

  • ビジネスルールを外部要素(UI, DB, フレームワーク)から独立させる
  • 依存性逆転の原則(DIP) を徹底し、変更に強いアプリケーションを実現する
  • テスト容易性や保守性を高める

層構造

  • Entities:ビジネスルール
  • Use Cases:アプリケーション固有のロジック
  • Interface Adapters:UI や DB をユースケースに適応させる
  • Frameworks & Drivers:具体的な実装(Android, iOS, DB, Web API など)

両者の違い

観点 MVVM Clean Architecture
カテゴリ UI アーキテクチャパターン アーキテクチャスタイル(全体設計)
適用範囲 表現層(UI 周辺) アプリケーション全体
依存関係 View → ViewModel → Model Framework → Adapter → UseCase → Entity
主な目的 UI とロジックの分離 ビジネスロジックの独立と依存性逆転
使用例 Android ViewModel, SwiftUI, WPF Android, iOS, Web, Backend 全般

両者の関係

Clean Architecture の中には 「Interface Adapters 層」 が存在します。
ここに MVVM を採用することで、UI 層を整理しつつ Clean Architecture の原則に従うことが可能です。

つまり:

  • MVVM = UI 層の設計パターン
  • Clean Architecture = アプリ全体の設計思想
  • Clean Architecture の中で MVVM を利用できる

図解(Mermaid)

ここで MVVM(Model-View-ViewModel)は、Clean Architecture の Interface Adapters 層の UI 部分に位置づけられます。


まとめ

  • MVVM は UI の設計パターン
  • Clean Architecture はアプリ全体の設計思想
  • 両者は競合ではなく、Clean Architecture の中で MVVM を取り入れる関係
  • 実際のプロジェクトでは、
    • 「UI 層:MVVM」
    • 「アプリ全体:Clean Architecture」
      のように組み合わせるのが一般的です。

0
0
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
0
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?