Question: What are the benefits of using a repository in Marshmallow

Issue #82 closed
Todd Flora created an issue

Our current configuration is FireDAC and Oracle. Is there a benefit of using the repository concept. Can you provide a bulleted list of what the benefits of using this would be?

Thanks,

Comments (4)

  1. Stefan Glienke repo owner

    As always there are different opinions out there (just do a google search for: repository pattern orm). You will see people telling you all the different pro and cons about it. Personally I think having a clean abstraction between your DAL and other layers. The arguments of course also differ depending on the programming language and libraries you are using.

    One of the advantages for us though is the possibility to generate queries depending on the interface (like in the proxy repository) or manually tune your SQL code without changing anything - clean encapsulation. I think Linas has some more ideas on how to be able to dynamically generate queries depending on the method name and signature (I don't remember exactly where that was from but similar to something in java spring or hibernate iirc) - just look into the proxy repository.

    There is also the possibility of mocking the repository easily for unit testing. You can just mock the repository and test your business code without asking what exactly is not working (is it the business code or the data access code, or the orm?)

  2. Linas Naginionis

    Stefan wrote some nice points. Martin Fowler has briefly described repository pattern here.

    Personally, I prefer to use this pattern because it abstracts what you can do with your domain objects. Repository is like a collection of your domain model. E.g., when I need to retrieve a Customer, I know that I should use CustomerRepository, etc. Also, there could be some cases when you can only retrieve a Customer but it is forbidden to save it. Repositories can encapsulate this behavior. They can also act as an persistence API of you domain object.

    Another huge benefit is testability. As Stefan mentioned, it's very easy to mock your repositories and test your business code, even without connecting to the real database.

    I'm planning to add more features to Marshmallow repositories in the future versions.

  3. Todd Flora reporter

    Thanks for your responses guys. I love patterns, just haven't been keeping up I guess.

    Todd.

  4. Log in to comment