I need to implement a class called Foo where I need to Get and Save through a data access.
I can imagine I need to classes, one is to access, get and save data from an XmlFile, and another is the service which returns objects through like queries (GetFooById, GetFooByLevel, …), that’s my first though. That’s the reason why I want to clarify this design and what things I need to separate.
I think you’re on the right track with the repository pattern.
You can do something like this
In this way the Foo object is decoupled by the storage concerns. And later if you want to use a db instead of xml, just write another implementation. The app will be using the interface so you don’t have to change anything else that the assignment of ‘repo’.