the clean architecture

参考
原文链接
四层详细讲解

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 clean system should be:

  • Independent of FrameWork
  • Testable
  • Independent of UI
  • Independent of Database
  • Independent of any external agency

the clean architecture_第1张图片


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 application

Use Cases(Interactors): orchestrate the flow of data to and from the entities

Interface 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 applicaton 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类型再次创建费劲。在确保可测试情况下应该重复创建。 ).

the clean architecture_第2张图片

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.

the clean architecture_第3张图片


Domain Layer

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

the clean architecture_第4张图片


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.

the clean architecture_第5张图片

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.

你可能感兴趣的:(框架)