简体   繁体   English

Android 中的 MVVM 存储库

[英]MVVM repository in android

Am working on a huge android project that has more than 50 APIs request and using the MVVM pattern, My question is: can I add all the requests in the same app repository or I must create a repository for each service?我正在处理一个拥有超过 50 个 API 请求并使用 MVVM 模式的大型 android 项目,我的问题是:我可以将所有请求添加到同一个应用程序存储库中,还是必须为每个服务创建一个存储库?

在此处输入图像描述

As others suggested in the comments you should first define the modules of your app and then create the corresponding Repositories.正如其他人在评论中建议的那样,您应该首先定义应用程序的模块,然后创建相应的存储库。 This way you can easily maintain and test your application.这样您就可以轻松地维护和测试您的应用程序。

I strongly suggest you to have a look on this https://github.com/nickbutcher/plaid and mostly this video https://youtu.be/Sy6ZdgqrQp0我强烈建议你看看这个https://github.com/nickbutcher/plaid主要是这个视频https://youtu.be/Sy6ZdgqrQp0

A good solution to this problem is, You must not implement all your API calling code to the same repository as it will become a massive single repository class.这个问题的一个好的解决方案是,你不能将所有 API 调用代码实现到同一个存储库,因为它会成为一个巨大的单一存储库类。 It will also be violating design principles ie rule of 30 as you are saying you have at least 50 APIs to work with.它还将违反设计原则,即30 条规则,因为您说您至少有 50 个 API 可以使用。 Also, it is not a good practice to modify a class, again and again, see Open Close Principle .此外,一次又一次地修改类也不是一个好习惯,请参阅Open Close Principle You can make multiple API calling classes under the same package name.可以在同一个包名下制作多个API调用类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM