首页 > 学院 > 开发设计 > 正文

项目架构 the clean architecture笔记

2019-11-08 00:30:22
字体:
来源:转载
供稿:网友

前言

这是一篇学习Clean架构的笔记,MVP本身是属于展现层的逻辑,对于小型项目可能方便很多,但是对于大型项目来说MVP并不足以使代码优化、依然会代码冗余。所以分层和模块化才是方向,clean架构就指出了这种架构的设计方式,所有本篇文章就做些clean架构的学习笔记。

原文: architecting-android-the-clean-way the-clean-architecture

The clean system should be:

quality software could be : not only about satisfying requirements, also should be robust, maintainable, testable, and flexible enough to adapt to growth and change.

the detail is :

Independent of FrameWorkTestableIndependent of UIIndependent of DatabaseIndependent of any external agency

like this

the Dependency Rule: source code dependencies can only point inwards and nothing in an inner circle can know anything at all about something in an outer circle.Entities: business object of applicationUse Cases(Interactors): orchestrate the flow of data to and from the entitiesInterface Adapters: convert data from the format most convenient for the Interactors and entities.PResenters and Controllers in here.Frameworks and Drivers: all the datails go,with the UI logic

An application would be separated to three different layer

Each layer uses its own data model so this independence can be reached.(the project uses datamapper to acheive the indepenices. 具体实施中还待商榷,毕竟同样的model类型再次创建费劲。在确保可测试情况下应该重复创建。 ).

layer

Presentation Layer:

here is about the login related with views and animations.here can be MVP 、MVVM or MVC.The activities and fragments here are only views,only exist UI logic.Presenters in this layer are composed with interactors, use callback to translate data in background thread.

presentation layer

Domain Layer

Business rules here: all the logic happens in this layer. communicate with outside using interfaces.

domain layer

Data Layer

All data needed for the application comes from this layer through a UserRepository implementation that uses a Repository Pattern with a strategy that, through a factory, picks different data sources depending on certain conditions. load data from this layer.

data layer

Testing

Presentation Layer: used android instrumentation and espresso for integration and functional testing.Domain Layer: JUnit plus mockito for unit tests was used here.Data Layer: Robolectric (since this layer has android dependencies) plus junit plus mockito for integration and unit tests.

扩展阅读: 说说Android的MVP模式


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表