简体   繁体   English

在Java中使用存储库模式时,可以将单个Manager / Controller用于3个不同的存储库吗?

[英]When using the Repository Pattern in Java, is it ok to use a single Manager/Controller for 3 different Repositories?

I have 3 repositories that need to communicate with each other. 我有3个需要彼此通信的存储库。 Can I handle the logic of all 3 repositories in a single Manager or is it a better practice to create different Managers for each Repository and make them communicate with each other using another Manager (that will directly communicate with the UI)? 我可以在一个Manager中处理所有3个存储库的逻辑,还是更好的做法是为每个存储库创建不同的Manager,并使它们使用另一个Manager(将直接与UI进行通信)相互通信?

Context: 内容:

It's basically an app for managing restaurant orders. 它基本上是一个用于管理餐厅订单的应用程序。

The 3 Repositories are: 3个存储库是:

  • ProductRepository - the available products ProductRepository-可用产品
  • TableRepository - all the tables in the restaurant TableRepository-餐厅中的所有桌子
  • OrderRepository - one order consists of a tuple (product_id, table_id) OrderRepository-一个订单包含一个元组(product_id,table_id)

The manager must validate the data, create Product, Table and Order objects and save them to the correct Repository. 经理必须验证数据,创建产品,表和订单对象并将其保存到正确的存储库。

If classes / resources depend up on one other, there is (these days) mostly a Dependency Injection framework, handling the creation of these resources, and also Injecting them, in those who need them. 如果类/资源相互依赖,那么(近来)大多数时候将有一个依赖注入框架,以处理这些资源的创建,并在需要它们的人中注入它们。

The best known DI libraries for Java are 最著名的Java DI库是

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

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