views:

652

answers:

3

Hi,

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

+10  A: 

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

Jeff Sternal
You can also say, ...is for creating several families of objects.
Saif Khan
+1  A: 

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.

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.

WorthiGe
+1  A: 

Check out Evan's perspective

Mantas K.