Android清洁架构用户酶

发布于 2025-01-28 01:30:20 字数 388 浏览 4 评论 0原文

我正在开发一个简单的应用程序。

  1. 用户将Recyclerview的元素导航到终点屏幕。
  2. 当将最后一个碎片滚动到片段的底部时,共享pref将状态保存到真实。然后下一个元素可用。
  3. LastFragment的按钮在单击时播放声音 我正在尝试根据清洁体系结构的原则来构建应用程序,但

我不明白用户赛在哪里。您能向我解释一下这里应该使用哪种用户酶?

I am developing a simple application.

  1. The user navigates through the elements of the RecyclerView to the end screen.
  2. When scrolling LastFragment to the very bottom of the fragment, the SharedPref saves the status to true. Then the next element becomes available.
  3. LastFragment has a button that plays a sound when clicked
    I'm trying to build an application according to the principles of clean architecture and

I don't understand where UseCase is. Could you explain to me which UseCase should be used here?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め可乐爱微笑 2025-02-04 01:30:20

您需要拥有类似的东西:

PersistEndWasreachDusecase

或您喜欢的任何名称都将称为:“ SavetosharePrefs”逻辑。

他们应该成为您的域层的一部分:

https://developer.android.com/topicer.com/topicer.com/topicer.com/topicer /架构/域层

但同时,您需要保持干净。这意味着您的逻辑不应该知道其节省状态的位置。它可能是DB,SharePrefs,远程服务器等。

这就是为什么您应该使用存储库模式:

https://developer.android.com/codelabs/basic-android-kotlin-kotlin-training-repository-pository-pattern#0

https://wwwwwww.raywenderlich.com/24509368-repository-posellich-repository-pose--repsority-patern-repositor-patern-pattern-pattern-with-with-with-jetpack-jetpack-compack-compack-compsose

因此,您还需要有一个数据层:

https://developer.android.com/主题/架构/数据层

但长话短说 - 干净的含义 - 您将业务逻辑放在内层。它们取决于在这些层中声明的界面。然后外层实现这些接口。

基本上,这是控制的反转。检查实心。

https://miro.medium.com.com/max/max/1400/1400/1* B4LEEV0PBMQVYOLUH -MCZW.PNG

根据图像 - 您按实现详细信息:外层中的房间,共享Prefs等。内部层是纯kotlin/java代码。它对实现细节一无所知 - 它们被接口隐藏。

You need to have something like:

PersistEndWasReachedUseCase

Or whatever name you like that will call the: "SaveToSharePrefs" Logic.

They should be part of your Domain Layer:

https://developer.android.com/topic/architecture/domain-layer

But at the same time, you need to be clean. This means that your logic should not know where it saves states. It might be a DB, SharePrefs, a remote server, etc.

That is why you should you a repository pattern:

https://developer.android.com/codelabs/basic-android-kotlin-training-repository-pattern#0

https://www.raywenderlich.com/24509368-repository-pattern-with-jetpack-compose

So you need to also have a Data Layer:

https://developer.android.com/topic/architecture/data-layer

But long story short - what clean means - You put your business logic in the inner layers. They depend on interfaces declared in these layers. And then outside layers implement these interfaces.

Basically this is an Inversion of control. Check SOLID.

https://miro.medium.com/max/1400/1*B4LEEv0PbmqvYolUH-mCzw.png

As per the image - you push the implementation details: Room, SharedPrefs, etc in the outer layers. And the inner layers are pure Kotlin/Java code. It knows nothing about implementation details - they are hidden by interfaces.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文