設計
こんな感じで考えています
全体像
View
Activity Fragment
View層
Application層
Domain層
Infra層
Presenter Service
UseCase
Entity
ValueObject
Repository
Memory Provider Prefs Api
SQLite
Presentation層
DDD + MVP
なぜDDDか?
ドメインロジックを
綺麗にプレゼンテーション層
と分けることができそうだっ
たから
なぜMVPか?
ActivityとFragmentをViewと
して扱えるから
ドメイン層
プレゼンテーション層
Controller
Model
View
タッチなどのイベント
Activityが
この位置に居るので
Model関連の処理を
Activityに書く事になる
Model View Controller
Activity
ドメイン層
プレゼンテーション層
Presenter
Model
View
タッチなどのイベント
Activityが
この位置に居るので
Modelと疎になり
書くべき事が減る
移譲
Model View Presenter
Activity
View、Activity、Fragment
View
Activity Fragment
View層
Application層
Domain層
Infra層
Presenter Service
UseCase
Entity
ValueObject
Repository
Memory Provider Prefs Api
SQLite
Presentation層
役割
• Viewの描画
• (イベントをPresenterに譲渡)
Presenter
View
Activity Fragment
View層
Application層
Domain層
Infra層
Presenter Service
UseCase
Entity
ValueObject
Repository
Memory Provider Prefs Api
SQLite
Presentation層
役割
• ドメイン層への伝達、Viewへの伝達
View
Activity Fragment
View層
Application層
Domain層
Presenter Service
UseCase
Entity
ValueObject
Presentation層
イベント
問い合わせ
View
Activity Fragment
View層
Application層
Domain層
Presenter Service
UseCase
Entity
ValueObject
Presentation層
結果通知
(非同期の時はEventBus)
結果をもとに
Viewへの反映依頼
UseCase
役割
• ドメインロジック
Repository
役割
• データの管理(CRUD)
ポイント
上の層のインスタンスは持てない
Domain層
Infra層
Presenter
UseCase
Repository
Presentation層
OK
OK
NG
NG
❌
❌
それをやると破綻する
実際には下の層のinterfaceを参照する
Domain層
Infra層
Presenter
UseCaseImpl
RepositoryImpl
Presentation層
<Repository>
<UseCase>
依存性をできる限りなくすため。あとテストしやすい。
参考になる
http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/
Android Clean Architecture
The Clean Architecture
http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
Androidの設計について
綺麗な設計について
GUI Architecture
http://martinfowler.com/eaaDev/uiArchs.html
Martinさんのいろんな設計手法について。MVCとかMVPとか。
http://terasolunaorg.github.io/guideline/5.0.0.RELEASE/ja/
ImplementationAtEachLayer/DomainLayer.html
ドメイン層の実装
あるFrameworkのどドメイン層の実装方法。
DDDちっくですごく勉強になる。

Android Architecture