Giter Club home page Giter Club logo

architectures's Introduction

architectures

送金プログラムのiOSサンプル(Swift)を,様々なソフトウェアアーキテクチャで実践したものです。

他のサンプルを見てもAPIに認証が必要であったり,画面がいくつもあったりして,アーキテクチャの勉強をしているのか,それとも他の複雑なプログラムの勉強をしているのか分からなくなります。

そこで,簡単な1画面のプログラムを,オフラインで動作するように作成しました。 比較がしやすいよう,git branchで切り換えるのではなく,UISplitViewControllerを用いて1画面で確認できるようにしました。

動作概要

WatanabeさんからTakahashiさんへ,一方通行にお金を送金するプログラムです。

  • RESETボタンを押すと,Watanabeさんは0に,Takahashiさんは1000に初期化されます。

  • TRANSFERボタンを押すと,Watanabeさんは-100,Takahashiさんは+100されます。

  • Watanabeさんが0の場合にTRANSFERボタンを押すとErrorのアラートが表示され,キャンセルされます。

screenshot

各アーキテクチャについて

PDS

概要

Presentation Domain Separationの略。プレゼンテーションロジックとドメインロジックが分離されることで,

プレゼンテーションとドメインの分離 - Martin Fowler's Bliki (ja)

  • プレゼンテーションロジックとドメインロジックが分かれていると、理解しやすい 同じ基本プログラムを、重複コードなしに、複数のプレゼンテーションに対応させることができる
  • ユーザーインターフェイスはテストがしにくいため、それを分離することにより、テスト可能なロジック部分に集中できる
  • スクリプト用のAPIやサービスとして外部化するためのAPIを楽に追加できる(選択可能なプレゼンテーション部分で見かける)
  • プレゼンテーション部分のコードは、ドメイン部分のコードと違ったスキルと知識が必要

のメリットを享受することができる。

(本リポジトリにおける) ディレクトリ構成

  • Presentation (inherited UIViewController)
  • Domain

依存ライブラリ

(なし)

参考

議論

(なし)

MVC

概要

Viewはアプリケーションの表示に関わるオブジェクトを定義し,ControllerはViewにおけるアクションの定義および遷移に関わる処理を,Modelにはデータおよびその処理を担う。 この時,ViewとModelはControllerを必ず経由し,ModelにはUIに関わるロジックは含まれない。 プレゼンテーションロジックとドメインロジックの分離に適した設計。

model_view_controller_2x.png https://developer.apple.com/library/archive/documentation/General/Conceptual/DevPedia-CocoaCore/Art/model_view_controller_2x.png

ちなみに,

MVC - Apple Developer

MVC is central to a good design for a Cocoa application. The benefits of adopting this pattern are numerous. Many objects in these applications tend to be more reusable, and their interfaces tend to be better defined. Applications having an MVC design are also more easily extensible than other applications. Moreover, many Cocoa technologies and architectures are based on MVC and require that your custom objects play one of the MVC roles.

と,Apple側の多くの設計はMVCに基づいていることが明記されている。

MVCの理解にはしばしば誤解があると言われる(議論を参照)。

(本リポジトリにおける) ディレクトリ構成

  • Model
  • View
  • Controller (inherits UIViewController)

依存ライブラリ

(なし)

参考

議論

MVP

概要

(本リポジトリにおける) ディレクトリ構成

  • Model
  • View (inherits UIViewController)
  • Presenter

依存ライブラリ

(なし)

参考

議論

MVVM

概要

(なし)

(本リポジトリにおける) ディレクトリ構成

  • Model
  • View
  • ViewModel (inherits UIViewController)

依存ライブラリ

参考

議論

(なし)

DDD

概要

(本リポジトリにおける) ディレクトリ構成

  • UserInterface (inherits UIViewController)
  • Application
  • Domain
  • Entity
  • Infrastructure

依存ライブラリ

(なし)

参考

(なし)

議論

(なし)

ReSwift

概要

(本リポジトリにおける) ディレクトリ構成

  • ViewController (inherits UIViewController)
  • Reducer
  • State
  • Actions

依存ライブラリ

参考

(なし)

議論

(なし)

ReactorKit

概要

(本リポジトリにおける) ディレクトリ構成

  • ViewController (inherits UIViewController)
  • Reactor

依存ライブラリ

参考

(なし)

議論

(なし)

VIPER

概要

viper_architecture-2000x720.jpg https://s3.amazonaws.com/ckl-website-static/wp-content/uploads/2016/04/viper_architecture-2000x720.jpg

(本リポジトリにおける) ディレクトリ構成

  • ViewController (inherits UIViewController)
  • Interactor
  • Presenter
  • Entity
  • Router
  • Protocols

依存ライブラリ

(なし)

テンプレート生成ツール

参考

議論

(なし)

Clean Architecture

概要

依存関係逆転の原則(Dependency Inversion Principle)によって

CleanArchitecture-8d1fe066e8f7fa9c7d8e84c1a6b0e2b74b2c670ff8052828f4a7e73fcbbc698c.jpg https://8thlight.com/blog/assets/posts/2012-08-13-the-clean-architecture/CleanArchitecture-8d1fe066e8f7fa9c7d8e84c1a6b0e2b74b2c670ff8052828f4a7e73fcbbc698c.jpg

(本リポジトリにおける) ディレクトリ構成

  • Application/
    • Wireframe
    • Builder
  • Data/
    • Repository
    • DataStore
    • Entity
  • Domain/
    • UseCase
    • Translator
    • Model
  • Presentation/
    • Presenter
    • UI/
      • View
      • ViewController (inherits UIViewController)

依存ライブラリ

テンプレート生成ツール

参考

議論

(なし)

RxFeedback

概要

RxFeedback.png https://github.com/kzaher/rxswiftcontent/raw/master/RxFeedback.png

(本リポジトリにおける) ディレクトリ構成

  • View
  • ViewController (inherits UIViewController)
  • State
  • Event

依存ライブラリ

参考

議論

(なし)

Realistic ViewController

概要

この設計で実装する最低限の機能を実装したViewController。保存処理も含めない。 「最低限動く」このVCにユーザー管理の分割や保存処理を追加したものが各アーキテクチャで構成される。

保存処理を実装していない為,値の保持や他のViewとの連携は行われない。

(本リポジトリにおける) ディレクトリ構成

  • ViewController (inherits UIViewController)

依存ライブラリ

参考

(なし)

議論

(なし)

他,まとめ,歴史,比較記事

まとめ

歴史

比較

終わりに

本リポジトリは,ソフトウェア設計における情報を統一しようと試みるものであり,設計そのもの及び歴史に関する誤謬を含んだものであることを断っておきます。本記事及びコードが正確であることを保証するものではありません。そもそも設計方針であって,単体で1アーキテクチャとして成立するとは言い難いものもあります。本リポジトリは全てのアーキテクチャを網羅するものではなく,それぞれを比較し,優劣をつけるような意図はありません。

architectures's People

Contributors

yutomizutani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.