在Flutter中为多个BLoCs使用相同的存储库

huangapple go评论50阅读模式
英文:

The same repository for several BLoCs in flutter

问题

使用相同的存储库来管理多个 BLoC 是一个好主意吗?

英文:

Is it a good idea to use the same repository for several BLoCs?

答案1

得分: 2

使用相同的存储库来管理多个Flutter中的BLoCs通常不被建议。存储库应该被创建以满足项目内特定功能或模块的数据需求,因为它通常负责维护特定数据源或API。如果每个BLoC都有自己的存储库实例,项目的架构将更加灵活和模块化。

通过为每个BLoC使用不同的存储库,您可以确保每个功能的数据需求都是独立和明确定义的。这使得测试和维护代码更加简单。此外,它使您能够更改一个方面而不影响其他方面。

然而,在某些情况下,共享存储库可能是合适的,比如当多个功能依赖于相同的数据源或数据非常简单,不需要自己的存储库时。在这些情况下,关键是要仔细权衡权衡权衡,并确保共享存储库以满足所有依赖于它的功能的需求的方式创建。

英文:

It is a broad question to be asked well according to me, using the same repository for many BLoCs in Flutter is typically not advised.

A repository should be created to fulfil the data requirements of a particular feature or module inside your project as it is often responsible for maintaining a specific data source or API. The architecture of your project will be more flexible and modular if each BLoC has its own repository instance.

You may make sure that the data requirements for each feature are distinct and well-defined by utilising different repositories for each BLoC. This makes it simpler to test and maintain your code. Also, it enables you to alter one aspect without altering others.

A common repository, however, could be appropriate in some circumstances, such as when several features rely on the same data source or when the data is straightforward and doesn't need its own repository. In these situations, it's crucial to carefully weigh the trade-offs and make sure the shared repository is created in a way that satisfies the requirements of all the features that depend on it.

huangapple
  • 本文由 发表于 2023年3月3日 23:11:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定