I was wondering if i can use the Repository Pattern for anything other than a database layer?
I have used the pattern for a shopcart where I stored shopcart items in an array in ShopCartRepository class. I then got the data from the ShopCartRepository using a ShopCartController class.
As mentioned the ShopCartRepository only deals with an array and therefore not a database.
Is this a “legal” approach for using the Repository Pattern?
The repository pattern is good for any situation in which you want to have a centralized place to control the creation, retrieving, modification and deletion of data proceding from a set, be it a database table, an in-memory list, or whatever; this power of abstraction is precisely what makes the pattern valuable. Of course it is legal to use it in any way that makes sense for your project.