Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

I assume you refer to the repository pattern by Martin Fowler.

He says:

Repository: Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.

He himself categorizes the pattern as "Object-Relational Metadata Mapping".

If you want to use the categories in the GOF book, I'd put it into the structural pattern category as the focus of this pattern is to present an interface/view to a client, similar to the Adapter/Facade/Proxy patterns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top