创建用户酶 - 干净的体系结构?

发布于 2025-01-25 22:33:09 字数 131 浏览 3 评论 0原文

我在存储库中很有趣,

fun getDogs()=apiService.getDogs()

我的问题是我应该为此功能创建用例吗?换句话说,如果功能没有业务规则,我应该为其创建用户酶吗?

I have simple fun in repository it get all dogs

fun getDogs()=apiService.getDogs()

My question is should I create use case for this function? in other words if function doesn't have business rules should i create useCase for it?

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

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

发布评论

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

评论(1

林空鹿饮溪 2025-02-01 22:33:09

根据良好的编程实践,最好创建用例。用例将以两种方式受益:

  • 在稍后的时间点,在存储库方法中的合同变更不会影响您的ViewModel实现。例如。存储库方法返回的数据更改,或者您想使用从存储库中的两种方法来整理数据,然后返回用例中。
  • 如果您正在做类似KMM之类的事情,那么拥有一个用例层将更加一致。

如果您的用例非常简单,并且您很确定存储库层的合同永远不会改变(理想情况下是一件坏事),那么您可以使用存储库直接继续进行。

As per good programming practices, it is better to create a use case. A use-case will benefit in two ways:

  • LA change in contract in the repository method at a later point in time would not affect your ViewModel implementation. eg. the data returned by the repository method changes or you want to use two methods from the repository to collate data and then return in your use-case.
  • If you are doing something like KMM, then having a use-case layer will be more consistent across.

If your use case is very simple and you are pretty sure that the contract from the repository layer would never change (which is ideally a bad thing to assume), then you may go ahead directly using the repository.

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