redigaffi
redigaffi

Reputation: 449

Repository Design pattern

I have a question about Repository design pattern, exactly how to interact with many data sources.

For example, i have these repositories:

(Is this even correct? i mean to create an repository for each data source?)

What is better:

Im not clear to how to retrieve an specific repository for an specific data source, if i use an abstract class, i could implement an UserFactory (factory pattern) class that returns me the specific repository object. (Is this even correct ?)

But how could i retrieve an specific repository if i use an interface? (Since factory pattern needs an parent abstract class, am i right?)

Also when i say "an specific repository" i mean receive a repository with its specific data source.

Thank you so much, redigaffi.

Upvotes: 0

Views: 159

Answers (1)

David Osborne
David Osborne

Reputation: 6781

What is better:

An abstract class called UserRepository and the other ones extend from UserRepository.

Just an interface for these 3 Repositories.

Start with whatever's simplest. IMHO, this is the interface. Add an abstract base class if the need arises.

But how could i retrieve an specific repository if i use an interface?

Use a factory that contains logic to determine which kind of repository to return.

Upvotes: 1

Related Questions