I've always used the repository pattern in my applications. But I have seen that many people use facades instead of the repository for naming convention, but the operation is the same, I Think. Why is there this difference? There are a real difference between them or not?
1 Answer
A facade is more general than a repository.
A facade can apply to anything that is not persistence based, whereas a repository is supposed to encapsulate access to an underlying source and make it look like an in memory data source.
Facades are for creating a simple interface for some other, complicated interface.
- So the repository is designed for communicate with data layer and facades is more generic than this. for example a facades can perform other operation but the structure in designed like a repository, right?Mirko– Mirko2014-03-14 11:52:07 +00:00Commented Mar 14, 2014 at 11:52
- 2@MirkoPastorelli - it can. An example of a facade would be to give a single entry point for code that actually has to deal with several subsystems.Oded– Oded2014-03-14 11:58:05 +00:00Commented Mar 14, 2014 at 11:58
- 5@MirkoPastorelli: a repository is not designed for communicating with the data layer, it is designed for wrapping the communication with a data layer and "abstracting this away" from the user of the repo. (so one can, for example, provide a mock repository for testing purposes which provides only hardcoded test data and has no other dependencies). From this point of view, a repo is indeed nothing but a specific form of facade.Doc Brown– Doc Brown2014-03-14 12:53:26 +00:00Commented Mar 14, 2014 at 12:53