Reputation: 23000
I am developing an application that has its own data access layer. In data access layer I have a class for each data object for storing and retrieving data in SQLite.
Now I want to add an extra feature to my application that let me to store and retrieve these data in Webservice. I mean I want to have 2 modes. One mode for interacting with SQLite and another mode for interacting Webservice in data access layer. I want to store my data to SQLite or a webservice optionally.
Assume that my webservice has its own Insert, Update, delete and select methods.
How can I do that? Is there any tutorials or example?
Thanks,
Upvotes: 0
Views: 936
Reputation: 35661
You would create an interface that has all the required update\delete etc methods and each storage area (local\web) you want to use would implement this interface.
At runtime you would pass in the relevant storage area object and operate against the interface. Your code would not need to know where the storage was, it needs only call the methods defined in the interface.
As an example, this is an interface I created to implement a file\folder chooser that operates on both SD card and Dropbox which is similar to your own requirements.
public interface IFileChooser {
public List<FileSystemItem> getItems(String Path, FileSystemItemFilter filter);
public Boolean CreateFolder(String Path, String FolderName);
public Boolean DeleteFolder(FileSystemItem itm);
public String getRoot();
public String getParentPath(String path);
public String getSeparator();
public Boolean isRemoteSource();
}
Upvotes: 2