Creating the POI storage interface

Now, we need to create a standard interface that will define the methods provided by the storage service. The interface will need to allow basic CRUD (create, read, update, and delete) operations. We would also like to provide basic caching capabilities. Caching can dramatically enhance app responsiveness by storing data that will likely be accessed multiple times in the memory locally and preventing multiple reads from a file or accesses to a web service.

To create the data service interface, perform the following steps:

  1. Select the POIApp project in the Solution pad in Xamarin Studio.
  2. Right-click on it and select New File.
  3. On the left-hand side of the New File dialog, select General.
  4. At the top of the template list, in the middle of the dialog, select Empty Interface (C#).
  5. Enter the name IPOIDataService and click on OK.
  6. Fill in the methods to support the CRUD operations and caching. You will need to also add a collection property for the caching of POIs based on IReadOnlyList. The use of IReadOnlyList ensures that POIs cannot be added directly to the cache but must be added or deleted through the CRUD operations.

The following example shows the interface's definition from the 9169_04_CodesPOIAppPOIAppIPOIDataService.cs from the code bundle of this book. Note that in this example, SavePOI() accounts for the create and update portion of CRUD.

  public interface IPOIDataService
  {
    IReadOnlyList<PointOfInterest> POIs { get; }
    void RefreshCache();
    PointOfInterest GetPOI (int id);
    void SavePOI(PointOfInterest poi);
    void DeletePOI(PointOfInterest poi);
  }
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.214.233