[英]Relevance of Clean Architecture Use Cases / Domain Layer
For few years I read articles about Android Architecture and Clean Architecture. 几年来,我读了有关Android体系结构和Clean Architecture的文章。
In the clean architecture, we usually have the 3 layers : Presentation (containing MVVM/MVP) - Domain (containing POJO and UseCases/Interactors) - Data (containing repositories implementation) 在干净的体系结构中,我们通常分为3层:表示(包含MVVM / MVP)-域(包含POJO和UseCases / Interactors)-数据(包含存储库实现)
In Android projects there is often only 2 layers : the presentation layer containing the MVVM stuffs, and the Data layer with the repositories. 在Android项目中,通常只有两层:包含MVVM内容的表示层,以及具有存储库的数据层。 The repositories are directly accessed from the ViewModel, and the data are processed in the ViewModel before passing them to the View.
可以从ViewModel直接访问存储库,并在将数据传递给View之前在ViewModel中对其进行处理。
So my question is : what would be the purpose of the UseCases/Interactors on Android ? 所以我的问题是:Android上的UseCases / Interactors的目的是什么? Are they relevant or can they be completely integrated to Android's ViewModel ?
它们是否相关,或者可以完全集成到Android的ViewModel中?
It depends on how you view your android app. 这取决于您如何查看自己的android应用。 If the App is purely a view layer, then no, they are not particularly relevant.
如果该应用程序纯粹是视图层,则否,它们不是特别相关。 If you are using it as more than a view-layer, and instead is a client application, then you would do well build a whole new layered application and not skip the UseCases and models of a clean architecture.
如果您不只是将其用作视图层,而是将其用作客户端应用程序,则可以很好地构建一个全新的分层应用程序,而不必跳过UseCases和干净架构的模型。
When to do this is purely a judgement call. 什么时候做这纯粹是一个判断电话。 For apps that have only trivial logic, and are used mostly as a presentation engine, with all the relevant business logic server-side, then you can probably get away with a viewmodel.
对于仅具有琐碎逻辑并且大部分都用作表示引擎的应用程序,以及所有相关的业务逻辑服务器端,那么您可能可以摆脱视图模型的束缚。 Many apps have as much or more complexity client-side than server-side, at which point you will want to design them in a way that the system scales and can be maintained.
与客户端相比,许多应用在客户端具有或多或少的复杂性,这时您将需要以系统可扩展和可维护的方式设计它们。
If you find yourself wondering where your UseCases belong, then you have probably crossed that threshold, and should design it as its own application. 如果您想知道UseCases属于什么地方,那么您可能已经超过了该阈值,应该将其设计为自己的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.