What is the difference between Factory Pattern and Repository Pattern?

 Posted by Niladri.Biswas on 7/19/2012 | Category: Design Pattern & Practices Interview questions | Views: 4662 | Points: 40

The factory pattern deals with how an object is created. It gets classified under the creational pattern.We can go for a factory pattern when we need for

a) Object creation without exposing it to client

b) Refer to newly created objects through interface.

Factory pattern defines an interface for creating an object, but let the classes that implement the interface decide which class to instantiate.

Repository pattern comes into use when we have (at a minimum) atleast one of the following requirements

a) We want to centrally manage the data by applying logic and reules while dealing with data that comes from varied location.

b) We need to use business entities that are strongly typed.These helps to find errors at comile time rather at runtime.

c) Isolate data layer for unit testing.

d) Want to have a caching mechanism in place to hold the data inorder to improve the application performance.

e) Seperate business logic and data layer logic for better code maintainability.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response