Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type is repository pattern in?

In general, I know that there are 3 big types of design pattern

  1. Creational Pattern (Factory, Singleton, etc)
  2. Structural Pattern (Composite, Adapter, Proxy, etc)
  3. Behavioral Pattern (Specification, Command, etc)

But I dont know which type I can put the Repository pattern in.

Is Repository pattern in one of three above type? Or is it kind of in the middle of (2) and (3) pattern?

like image 501
Vu Nguyen Avatar asked Apr 22 '14 07:04

Vu Nguyen


People also ask

What type of pattern is repository pattern?

The Repository pattern implements separation of concerns by abstracting the data persistence logic in your applications. Design patterns are used as a solution to recurring problems in your applications, and the Repository pattern is one of the most widely used design patterns.

Is repository pattern a architecture?

The Repository pattern was introduces in the book Patterns of Enterprise Application Architecture which was released after the GOF book. From it's definition: A Repository mediates between the domain and data mapping layers... we can say that it's a Structural pattern.

What is the repository pattern used for?

The Repository pattern allows you to easily test your application with unit tests. Remember that unit tests only test your code, not infrastructure, so the repository abstractions make it easier to achieve that goal.

Is repository pattern a facade pattern?

The repository pattern is a popular facade pattern for a set of implementations with common persistence features. Let's check it out!


2 Answers

Repository can be viewed as a special kind of Façade (structural) but also as a special kind of Factory (creational). Also, as the Repository often expose collection-like interface, then it might be a special application of Iterator (behavioral).

What I am trying to say is that neither those categories nor patterns themselves are any sort of definite doctrine. There are just some ideas and a language that tries to make them more explicitly visible. These categories are just helpers trying to express somehow what some patterns do. Also patterns are just various expressions of a generic loose coupling principles. Their borders are blurry.

like image 176
Bartłomiej Szypelow Avatar answered Sep 19 '22 16:09

Bartłomiej Szypelow


A repository is a specialisation of the Facade pattern which is structural.

like image 36
devdigital Avatar answered Sep 23 '22 16:09

devdigital