简体   繁体   English

干净的架构用例/领域层的相关性

[英]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.

相关问题 使存储库在 Clean Architecture 的域层中不可见 - Make repository invisible in domain layer of Clean Architecture 在干净的架构中结合用例/交互器 - Combining Use Cases/Interactors in Clean Architecture 干净的体系结构:在域或演示文稿/应用程序中使用CompositeDisposable - Clean architecture: Use CompositeDisposable in domain or presentation/app 使用 paging3 清理架构并组合将 PagingData 传递到域层 - Clean Architecture with paging3 and compose passing PagingData to domain layer Room Entity 和 Clean architecture Domain 层的 Entity 是不同的吗? - Is Room Entity and Clean architecture Domain layer's Entity is different? 从Kotlin的干净架构定义用例的惯用方式 - Idiomatic way to define use cases from clean architecture in kotlin 可以在 Clean Architecture 的上下文中在数据层中调用用例吗? - Can a use case be called in data layer in context of Clean Architecture? 将上下文传递给 android 中的域层(用例)是一种好习惯吗 - Is it good practice to pass the context to the domain layer (Use cases) in android 我可以将自定义类导入到领域层的用例中吗? - Can I import custom classes into Use cases of the Domain layer? 干净的体系结构:域层是否应在特定操作后控制是否添加到数据库? - Clean Architecture: Should the domain layer control whether add to database or not after specific action?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM