The "Repository" pattern for which a name could not be suggested here is really just an example of the Factory pattern as best as I can tell. This serves as ammunition to boost my assertion methinks. Also, this problem of not wanting to have testers retest working code could perhaps be alleviated in the OCP purist paradigm that few of us really wrap our ways around.
Perhaps this isn't that clear. I write for a second time today, having slept on what I wrote above. This suggests that Eric Evans thinks that there is a difference between factories and repositories in that repositories get the data and then the factories compose the data downstream in a second step. I guess if I were not using NHibernate and I were using a stored procedure to grab data in a repository, the dataset would then be run through a factory to cast it to a domain object. Moreover, I began feeling self-doubt about what I wrote above out of realizing that saves and updates to objects don't necessarily return much from repositories and thus might break with the whole factory notion. Hmmm... you are still going to a repository to get an object that you should not just new up cowboy-style outside of the repository so it really feels like this is functionally a variant of the factory pattern with the fact that you can hand stuff back in really just meaning that the "factory" itself may be tweaked. Assuming an onion architecture, you ought to be able to pull all database interactions out of your repositories and replace them with POCOs stored in session or static state or the cache or something and have all the unit tests still pass, and then the only differentiation from a purist factory pattern would be that the underlying state may be tweaked. We are not supposed to care from the outside looking in how this external dependency does what it does, we just call methods on it. As suggested here, we are asking for objects we dare not instantiate and thus the similarity is strong, repository pattern to factory pattern that is, even if repository and factory mean two different things to Mr. Evans as standalone terms not leading the word "pattern."
No comments:
Post a Comment