Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between a repository and factory pattern

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

like image 333
Blankman Avatar asked Jul 09 '09 14:07

Blankman


People also ask

What is difference between factory and repository pattern in Magento 2?

Factories are service classes that instantiate non-injective classes, that is, models that represent the database entity. They create an abstraction layer between ObjectManager and the business code. The repository object is responsible for reading and writing information about your object to the object store.

What is a repository pattern?

The Repository pattern. Repositories are classes or components that encapsulate the logic required to access data sources. They centralize common data access functionality, providing better maintainability and decoupling the infrastructure or technology used to access databases from the domain model layer.

What is the difference between factory and prototype patterns?

Factory pattern is used to introduce loose coupling between objects as the factory will take care of all the instantiation logic hiding it from the clients. Prototype pattern on the other hand is used when the cost of creating an object is large and it is ok to copy an existing instance than creating a new instance.

What is a key difference between the factory and Singleton patterns?

The Singleton pattern ensures that only one instance of the class exists and typically provides a well-known, i.e., global point for accessing it. The Factory pattern defines an interface for creating objects (no limitation on how many) and usually abstracts the control of which class to instantiate.


1 Answers

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

like image 62
Jeff Sternal Avatar answered Sep 24 '22 06:09

Jeff Sternal