1

One of the major benefits of the repository pattern is that you can easily switch out implementations for other implementations.

After learning about this pattern I started to make tons of things into repositories like an HttpClient repository for example, this way I can decide which client I want to use. Another example is a NumberGenerator repository which can either be implemented with just random number generation, or other times it generates a number by looking something up on the web.

But then I needed to store things in the database so I was thinking of having something like this:

Repositories/
  Number/
    NumberGenerator/
      NumberGeneratorContract
      RandomNumberGenerator
    NumberStore/
      NumberStoreContract
      DbNumberStore

But that seems a little awkward, to have to call something a store for storing it, if repository itself really means a place to store things.

Am I misusing the repository pattern?

3

The repository pattern is meant to hide implementation details regarding data persistance.

In that regard I'd say you are misclassifying the objects you are talking about. They seem to rather be business logic services, connectors/"drivers" or facades. Depends on how general they are I guess...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.