存储库和工厂模式之间的差异

时间:2022-01-31 13:20:58

Can you please outline the differences between the Repository pattern and the Factory pattern?

你能否概述一下Repository模式和Factory模式之间的区别?

2 个解决方案

#1


The Factory pattern is for creating objects, while the Repository pattern describes a general method of encapsulating CRUD operations against a data source.

Factory模式用于创建对象,而Repository模式描述了针对数据源封装CRUD操作的一般方法。

#2


The repository pattern deals with creating a set of data access services, ie. CRUD methods. The factory pattern on the other hand deals with how an object is created. A factory class will have a method that returns a new instance of a class.

存储库模式处理创建一组数据访问服务,即。 CRUD方法。另一方面,工厂模式处理对象的创建方式。工厂类将有一个返回类的新实例的方法。

The two are independent of each other; however, you will often see the factory pattern used alongside with the repository pattern in order to create a new instance of a entity.

两者是相互独立的;但是,您经常会看到与存储库模式一起使用的工厂模式,以便创建实体的新实例。

#1


The Factory pattern is for creating objects, while the Repository pattern describes a general method of encapsulating CRUD operations against a data source.

Factory模式用于创建对象,而Repository模式描述了针对数据源封装CRUD操作的一般方法。

#2


The repository pattern deals with creating a set of data access services, ie. CRUD methods. The factory pattern on the other hand deals with how an object is created. A factory class will have a method that returns a new instance of a class.

存储库模式处理创建一组数据访问服务,即。 CRUD方法。另一方面,工厂模式处理对象的创建方式。工厂类将有一个返回类的新实例的方法。

The two are independent of each other; however, you will often see the factory pattern used alongside with the repository pattern in order to create a new instance of a entity.

两者是相互独立的;但是,您经常会看到与存储库模式一起使用的工厂模式,以便创建实体的新实例。